PHP Switch Code doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

PHP Switch Code doesn't work

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Switch Code doesn't work

Post by Christopher »

Maybe it was a typo, but the URL should be ?a=1&b=1
(#10850)
Post Reply