Display default image if not in database


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.