Else If statement not workin

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
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Else If statement not workin

Post by blade_922 »

Hey


Here's part of my code where the else if starts

Code: Select all

$theplatform=$row[platform];
$platform1='0';

if ($theplatform=ps3)  { $platform1="images/consoles/old/ps3.gif"; }
elseif ($theplatform=psp) { $platform1="images/consoles/old/psp.gif"; }
elseif ($theplatform=x360) { $platform1="images/consoles/old/x360.gif"; }
elseif ($theplatform=ds) { $platform1="images/consoles/old/ds.gif"; }
elseif ($theplatform=wii) { $platform1="images/consoles/old/wii.gif"; }
else { echo "nothing."; }

  //fill the array with your data 
  $mydata[] = "<table class=\"myown\" cellpadding=\"0\" border=\"0\" align=\"center\"><tr><td colspan=\"2\" $tdreg><center><img border=\"0\" src=\"thumbnailer.php?image=" .$row['url'] ."&type=Media\" border=\"0\"></center></td></tr><tr><td colspan=\"2\" $tdreg2>$row[title]&nbsp;<img src=\"$platform1\"><td></tr><tr><td $tdreg>Updated:</td><td $tdreg>$row[date]</td></tr></table>"; 

}
the console image is displayed ($platform1)
Okay so for some reason it keeps showing the image images/consoles/old/ps3.gif next to each screenshot instead of the correct image depending on what the database has it as.

Ive tried everything.

Any ideas?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

1. "=" means "set value to", while "==" means "equal to"
2. use single or double quotes arround your strings. I.e. instead of ps3 you should use "ps3" or 'ps3'
There are 10 types of people in this world, those who understand binary and those who don't
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

Hey cheers.

Im not new to php but im no expert lol. Im still picking up on little things and i guess you learn from your mistakes. I wont be making this mistake again.

Cheers bud
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I would do something like this..

Code: Select all

$platimages = array('ps3'  => 'ps3.gif',
                    'psp'  => 'psp.gif',
                    'x360' => 'x360.gif',
                    'ds'   => 'ds.gif',
                    'wii'  => 'wii.gif');

$platform1 = 'images/consoles/old/' . (isset($platimages[$theplatform]) ? $platimages[$theplatform] : 'default.gif');
Also, be sure to encapsulate your strings in quotes or PHP is thinking that your looking for the value of a constant. It works because if the engine can't find a constant with that name it will interpret it as a string.
Post Reply