forumnz Posted February 17, 2007 Share Posted February 17, 2007 Ok, I tried on another post but I was probably too confusing. I really want to know how to display image 'a' if a database entry is equal to '1' and to display image 'b' if the database entry is equal to '0'. How can I do this please? Thanks. Quote Link to comment Share on other sites More sharing options...
arifsor Posted February 17, 2007 Share Posted February 17, 2007 if($row['val'] == 1) $img = "a"; else if($row['val'] == 0) $img = "b"; Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 in this example we use the link direct to the folder path but you can also use the table colum for that ok. image_number is a int or a enum set 0 or 1 ok. <?php $database=mysql_connect("localhost","username" , "password"); mysql_select_db("database name",$database); $query="select * from images"; $result=mysql_query($query); while($img=mysql_fetch_assoc($result)){ $image_num=$img['image_number']; if($image_num==1){ echo"<img src='www.what_ever.com/image0.jpg'></img>"; }elseif($image_num==0){ echo"<img src'www.whatever.com/image1.jpg'></img>"; }else { echo" sorry there is no images to show"; } } ?> Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks - how do I make it so that it finds the data in a row named 'row1' for instance? Does that make sense? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 what the database name and the column name please. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Database name is 'test' and table name is 'members' and row name is 'stg1' Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 set the column to 0 or 1 you should get iver a pic from google ok <?php //just fill this in ok. $database=mysql_connect("localhost","username" , "password"); mysql_select_db("test",$database); $query="select * from memebrs"; $result=mysql_query($query); while($img=mysql_fetch_assoc($result)){ $image_num=$img['stg1']; if($image_num==1){ echo"<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'></img>"; }elseif($image_num==0){ echo"<img src='http://images.google.co.uk/intl/en_ALL/images/images_hp.gif'></img>"; }else { echo" sorry there is no images to show"; } } ?> Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 It came up with this error? Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/designervision.co.nz/httpdocs/clients/progress.php on line 80 Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 use the correct database name ? fully works here mate Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 $query="select * from memebrs"; sorry? change idone it yet m8t to members ok Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks but it now displays the same image 2 times and the images doesnt change if I make 0 become 1 in the database. Quote Link to comment Share on other sites More sharing options...
forumnz Posted February 17, 2007 Author Share Posted February 17, 2007 Ok now I have the second image working (it changes depending on 1 or 0) but the first image wont go away. What do I do? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 maybe this dont no <?php ($image_num>1){ ($image_num<1){ ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.