Posted By

blantonious on 12/22/11


Tagged

mysql php


Versions (?)

Display default image if not in database


 / Published in: PHP
 

If the image source is not in the database a default image is displayed.

  1. //Retrieves data from MySQL
  2. $data = mysql_query("SELECT * FROM db*****") or die(mysql_error());
  3.  
  4. //Puts it into an array
  5. while($info = mysql_fetch_array( $data ))
  6. {
  7. ?>
  8.  
  9. <div class="member">
  10. <div class="imageSection">
  11. <?
  12.  
  13. if($info['photo'] == '')
  14. {echo "<img class=\"memberImage\" src=images/default.jpg>";}
  15. else {echo "<img class=\"memberImage\" src=images/".$info['photo'] .">";}
  16. ?>
  17. </div>
  18. </div>

Report this snippet  

You need to login to post a comment.