Page 1 of 1

PHP Switch Code doesn't work

Posted: Sun Aug 23, 2009 9:58 pm
by wiseguy12851
The following is a code snippet from a PHP file that sends back the correct image, after I get it working correctly I'll move it into a mysql database table for better management and flexibility.

The problem is that it doesn't work correctly, as you can see in the comment below if you send in the URL ?a=1?b=1 it passes into case 1 but the next case returns EB or the default case rather than case 1 again. I have tried ( case "1" ) as well

Code: Select all

$inum = $_REQUEST["a"];
$idisp = $_REQUEST["b"];
// inum = image number
// idisp = Display Type
// Type 1 - Echoes IMG Tag
// Type 2 - Echoes Image URL
// Wrong Image Number echoes EA
// Wrong Image Type echoes EB
 
$image0 = "/images/testimage.png";
 
switch($inum)
{
    case 1:
    switch($idisp)
    {
        case "1":
        echo "<img src='".$image0s."'>";
        break;
        
        case 2:
        echo $image0;
        break;
        
        default:
        echo "EB";
    }
    break;
    
        default:
        echo "EA";
}
There has to be something wrong with the case coding as even if there was something wrong the the coding inside it should break or produce an error.

Re: PHP Switch Code doesn't work

Posted: Mon Aug 24, 2009 1:25 am
by Christopher
Maybe it was a typo, but the URL should be ?a=1&b=1