PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a switch statement which checks conditions for values in a MySQL DB and should returned 'Unavailable' if a value is 0 and 'Available' if a value is 1. But at the moment the first check runs fine but the rest return both results. Can somebody help me please.
My code is:
I want it to run through each condition and check though. If I break out after the first condition statement is true then it doesn't run through the rest of the switch loop.
My expected output was something along the lines of:
lowloader: Available
articflatbed : Available
car : Unavailable
vantautliner: Available
If I used an IF statement for every single condition it would work. Eg
I was certain I'd learned from tutorials that switch statements were used in place of IF statements when the amount of conditions got quite large. I will revise the use of switch statements now though.
impulse() wrote:I was certain I'd learned from tutorials that switch statements were used in place of IF ELSE statements when the amount of conditions got quite large. I will revise the use of switch statements now though.
impulse() wrote:I was certain I'd learned from tutorials that switch statements were used in place of IF ELSE statements when the amount of conditions got quite large. I will revise the use of switch statements now though.
Stephen,
The trick is to switch on true, not the variable you're testing...