homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

pointers to show a field if/else

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

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)

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.



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

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 :)

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

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


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved