php - If image exists show else hide it -


I have the following status.

If there is no image in the DB, the page shows a large image placeholder. What is the best way to hide the image placeholder if no image is present?

  & lt; Img src = "& lt ;? php echo '../img/artists/' $ .rl_secret ['artist photo'] ;? gt; width =" 100% "/>   

You can do this if / else such statement :

  // I like to set things with variables $ placeholder_img = "../img/artists/placeholder.jpg"; $ Db_img = $ row_rs Accent ['Artist photo']; If ($ db_img) {$ img_src = $ db_img; } And {$ img_src = $ placeholder_img; } Echo "& lt; img src = '$ img_src' alt = '' width = '100%' / & gt;";    

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -