Welcome to WebmasterWorld Guest from 54.197.171.28

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

pointers to show a field if/else

   
1:35 pm on Sep 4, 2010 (gmt 0)

5+ Year Member



basically what i want to do is display a field (a photo) if another field has the value of 1 - or not show it if its 0

when the record is inserted into the db one of the form fields will be a simple 1/0 - so if i'm adding a record but not adding a photo with it i'll use 0 and vice versa

when i query the database to display results this is what i have now (stripped down version)

while ($row=mysql_fetch_assoc($query)){
echo("<br />" . $row['comments']. "<br /><img src='" . $row["photo"] . "' width=300 border=0 /> ");


an idea of where i go from here would be great :)
2:01 pm on Sep 4, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there adeibiza,

So basically you just want to show something depending on whether the value from the DB is 0 or 1. Well that's easy enough, Pseudo code:-

if(DATA_FROM_DB == 1){
//case is true show the picture
}
else{//you needn't have the else, but if you want another pic
//case is false show the default picture
}

or ternary:-

echo ((DATA_FROM_DB == 1) ? 'case true show picture':'case false show default');

Hope that makes sense.

Cheers,
MRb
2:27 pm on Sep 4, 2010 (gmt 0)

5+ Year Member



it did but i then thought why not just hide or show depending on whether the field was empty then i dont need the extra field :)

if(!empty($row['photo']))
{
echo (" <img src='images/cal/" . $row["photo"] . "' /> ");
}

but thats great because it gives me an idea for something else i wanted to do :)

thanks!