sh0wtym3 Posted April 1, 2009 Share Posted April 1, 2009 My script in a nutshell: if ($_GET["cmd"]=="1") { show table 1 }; if ($_GET["cmd"]=="2") { show table 2 }; if ($_GET["cmd"]=="3") { show table 3 }; So by going to www.mysite.com?cmd=1 you will see table 1. But I want to show a default table, let's name it table 4, to show when no $_GET variable is set. So by going to www.mysite.com you will see table 4. How do I accomplish this? I thought by simply adding an else statement at the end it would work (shown below), but it doesn't. if ($_GET["cmd"]=="1") { show table 1 }; if ($_GET["cmd"]=="2") { show table 2 }; if ($_GET["cmd"]=="3") { show table 3 }; else { show table 4 } Quote Link to comment https://forums.phpfreaks.com/topic/152096-solved-using-if-statements-and-_get-variables/ Share on other sites More sharing options...
premiso Posted April 1, 2009 Share Posted April 1, 2009 I would use a case/switch. <?php $cmd = isset($_GET['cmd'])?$_GET['cmd']:0; switch($cmd) { default: case "0": //show default table break; case "1": //show table 1 break; case "2": //show table 2 break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152096-solved-using-if-statements-and-_get-variables/#findComment-798768 Share on other sites More sharing options...
viion Posted April 1, 2009 Share Posted April 1, 2009 Do it like this: switch ($_GET[cmd]) { default: include "table4file"; break; case '1': include "table1file"; break; case '2': include "table1file"; break; case '3': include "table1file"; break; } If your Tables are in the same file or come from a function replace include "filename"; with function-name(); Similar to what got posted above me, i was to slow =X Quote Link to comment https://forums.phpfreaks.com/topic/152096-solved-using-if-statements-and-_get-variables/#findComment-798769 Share on other sites More sharing options...
sh0wtym3 Posted April 1, 2009 Author Share Posted April 1, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/152096-solved-using-if-statements-and-_get-variables/#findComment-798782 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.