Jump to content

Recommended Posts

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 }

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;
}

?>

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.