illuz1on Posted April 23, 2007 Share Posted April 23, 2007 I have this piece of code which will show what I intend on doing... <? $selection = $_POST["selection"]; if( $_GET["action"] == "clubs" ){ echo "CLUUUBS!"; } elseif( $_GET["action"] == "bars" ){ echo "BARRRS!"; } elseif( $_GET["lounges"] == "lounges" ){ echo "Lounges!"; } elseif( $_GET["events"] == "events" ){ echo "EVENTS"; }else { echo "No selection Made"; } ?> How can I make that work? the last 2 if's wont work Thanks guys Link to comment https://forums.phpfreaks.com/topic/48361-if-elseif-but-what-if-you-have-5-things-to-if/ Share on other sites More sharing options...
fert Posted April 23, 2007 Share Posted April 23, 2007 you go from $_GET['action'] to $_GET['lounges'] and $_GET['events'] Link to comment https://forums.phpfreaks.com/topic/48361-if-elseif-but-what-if-you-have-5-things-to-if/#findComment-236432 Share on other sites More sharing options...
Psycho Posted April 24, 2007 Share Posted April 24, 2007 Also, a switch() would be more apropos for this situation: switch ($_GET["action"]) { case 'clubs': echo 'CLUUUBS!'; break; case 'bars': echo 'BARRRS!'; break; case 'lounges': echo 'Lounges!'; break; case 'events': echo 'EVENTS'; break; default: echo 'No selection Made'; break; } Link to comment https://forums.phpfreaks.com/topic/48361-if-elseif-but-what-if-you-have-5-things-to-if/#findComment-236567 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 Switches are nice, but if you don't want to use a switch, I find that a more vertical approach helps... Not that the above switch would work... <?php $selection = $_POST["selection"]; if ( $_GET["action"] == "clubs" ) { echo "CLUUUBS!"; } elseif ( $_GET["action"] == "bars" ) { echo "BARRRS!"; } elseif ( $_GET["lounges"] == "lounges" ) { echo "Lounges!"; } elseif ( $_GET["events"] == "events" ) { echo "EVENTS"; } else { echo "No selection Made"; } ?> You say the don't work? What aren't they doing? Do you mean when $_GET["action"] equals "clubs", $_GET["lounges"] does NOT equal "lounges"? That would be because of your logic. If both are true, then only the first will work. If you want all of them to work at a time try this: <?php $selection = $_POST["selection"]; if ( $_GET["action"] == "clubs" ) { echo "CLUUUBS!"; } elseif ( $_GET["action"] == "bars" ) { echo "BARRRS!"; } else { echo "No selection Made"; } if ( $_GET["lounges"] == "lounges" ) { echo "Lounges!"; } else { echo "No selection Made"; } if ( $_GET["events"] == "events" ) { echo "EVENTS"; } else { echo "No selection Made"; } ?> That would work kinda funny though... Link to comment https://forums.phpfreaks.com/topic/48361-if-elseif-but-what-if-you-have-5-things-to-if/#findComment-236573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.