0

Hey guys I am pulling images to my front end using this PHP:

echo '<img class="ms-thumb" src="'.(explode(',', $cardata["PictureRefs"])[0]).'" alt="'.$cardata["Variant"].'" />';

So I'm taking images from my database and displaying them in a list, in rare cases some SQL rows wont have an image url.

Can anyone show me an example of code that I could use to display a placeholder image if the src="" is empty?

I'm not great with JS and I'm guessing I'll need to use it to accomplish this.

Any example of how this could be done would be great.

A.B
  • 20,110
  • 3
  • 37
  • 71
  • Looking for some stuff like this ? http://stackoverflow.com/questions/3984287/how-to-show-alternate-image-if-source-image-is-not-found-onerror-working-in-ie – PrakashSharma Oct 26 '14 at 15:29

1 Answers1

2

edit simple line, this will place image if image is empty (not there). replace src attribute with this one

   src="'.(!empty( $cardata["PictureRefs"]))?(explode(',', $cardata["PictureRefs"])[0]):'img/placeholder.jpg' .'"

where your path to img is

'img/placeholder.jpg'

change it to your placeholder path

A.B
  • 20,110
  • 3
  • 37
  • 71