fesan Posted February 25, 2009 Share Posted February 25, 2009 Hi... Having trouble to get this to work $chose_background = mysql_num_rows($result); switch($chose_background){ case " >10 ": echo "post some code"; break; case " >5 ": echo "post some other code"; break; case " >1 ": echo "post some totally different code"; break; default: echo "post the defoult code"; } Cant seem to get the value to react at the right case.... When it is like this the value that should go under case defoult ends up in case >10, and the rest ends up in defoult.... Quote Link to comment https://forums.phpfreaks.com/topic/146896-switch-case-with-number/ Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 Switch/Case cannot evaluate if x is greater than y. You need to use an if/elseif/else statement to handle that. Quote Link to comment https://forums.phpfreaks.com/topic/146896-switch-case-with-number/#findComment-771234 Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 but yuo can do <?php $chose_background = 4; switch($chose_background){ case $chose_background >10 : echo "post some code"; break; case $chose_background >5 : echo "post some other code"; break; case $chose_background >1 : echo "post some totally different code"; break; default: echo "post the defoult code"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146896-switch-case-with-number/#findComment-771257 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 but yuo can do I can say I did not know that, granted I would see that as dismissing the point of a switch/case....but I could see different usages for it...I guess. Quote Link to comment https://forums.phpfreaks.com/topic/146896-switch-case-with-number/#findComment-771259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.