In general, you have a number of options - some need more preplanning however.
Doctor, It Hurts When I Do That
If characters are frequently getting caught in situations where they don't have anything to do, they are not playing the long game very smart. They should consider these times in builds, when purchasing magic items, etc. "Oh I'm a melee guy if someone's in the air I'm borked" or "Oh I am a rogue I'm useless against undead" aren't things to try to fix while they're happening, they are things to plan for and say "how can I be maximally effective in a fight when these things come up?" The action economy is the most valuable thing in D&D combat, and losing actions is like having a -4 penalty to all actions on yourself. Just buying a couple tanglefoot bags takes many combats from "I am standing here in the back rank touching myself" to "aha, zombie entangled!" Keep a spare weapon of a different type, buy a couple potions, etc. If you don't bother planning ahead, this'll happen to you a lot. Incorporeal, flying, DR'ed enemies... Sometime it's as easy as "take a damn throwing axe off a corpse sometime and keep it around."
GMs, you can try drops and/or advice for noob players getting caught in this trap. Sadly in D&D 3e+ they are tempted to sell of "nonoptimized" items to put all their money into further minmaxing their set of "optimized" items. Happened last week in my game, I said like 10 times "you're sure you want to sell those unique weapons you got from sunken Azlant just to put another plus on your armor? Really? Really? Everyone else agree with that?" Sometimes players are immune to help from the GM though.
Check the Rules
3.5e has a lot of built in options you can use. Improvised weapons, aid another, etc. Check your skills. Can you use Knowledge skills to determine things about your foes and inform your teammates? Can you climb above the guy? Can you search for weapons/magic/clues/his phylactery while the fight's going on? Intimidate or taunt him? Remember you don't have to have ranks in most skills to try it.
If your build is such that this happens a lot, look for options to grant actions to others - there's various spells, class abilities, etc. that let you do something to basically exchange your action for others doing something.
Also, be smart. Sometimes a player will get frustrated "because they just can't hit" the enemy - and then upon review they are flurrying blows and power attacking. Well, no s*it Sherlock, drop those negatives off yourself. Sometimes people plain overlook options that are "suboptimal"/different from what they use every round of every normal fight - like you're used to doing huge damage with your sword, so then when skeletons attack you cry about how you can't hurt them through their DR and don't realize you could just punch them. (Players often translate "I can't do 30 points of damage to them this round" as "I am useless and can do nothing," but every hp helps.) Take cover, use full defense, delay and interrupt spellcasters, grapple and trip even if you don't have the feats - use all the options the rules present you with.
Screw the Rules
Tactics go beyond rules. If positioning is the problem, your team tactics suck. This is the single largest cause of this complaint. Some overeager charge-fighter will get foes in a corner where others can't get to them, or no one bothers to step to help the rogue set up sneak attacks, or the wizard decides to just pop fireballs instead of casting fly on the fighter.
But also, feeling constrained to the ruleset is a problem. Some folks who have come to RPGs from computer gaming think that all they can do is whatever their palette of rules options present to them. Using the environment like swinging from the chandelier or knocking a pillar down on someone, stunts, whatever. "How do I come up with cool things to try during combat" is the topic of a whole other question, but to get started try "watch action movies and take notes." D&D 3e+ kinda promotes this mindset by trying to have a rule for everything, but you should understand that's "a corrosive effect they've had on the hobby" and not "the way the game should work."
Punt
If the combat's well in hand, then roleplay or loot or play a stirring theme song. Or go bind the wounds of a downed enemy for later interrogation. Or heal a friend. There's a lot more to do in the game than "spam the kill button."
Heck, we were in one combat where we were down to one hobgoblin fighting the whole party. He just would not surrender, out of the general bullheadedness only D&D monsters have. I was so annoyed at his "poor AI" that rather have my samurai just kill him, I let the blind gnomish oracle kill him with his morningstar (I stood by and aided the gnome's AC so he wouldn't get hurt). "Surrender or you will die in shame and face your god having been slain by a blind gnome!!!" I yelled at him, over like 10 rounds until he succumbed to the death of a thousand cuts. If there's not a lot of threat left over (turned zombies, for example) - have some fun with it.