Jump to content


Image Display/No image - easy if you know how!

  • Please log in to reply
1 reply to this topic

#1 caldridge1

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 04 March 2006 - 04:39 PM

Hi all,
This is probably very simple to do, but I haven't got a clue how to do it.

I have a MySQL database that stores information for car classified ads. One of the fields in the database is image, which stores the path of the image for the ad - something simple like "/classpics/1.jpg".

Now, not all of the ads have images, but because of my somewhat amateur coding, the path to where the image should be is always inserted into the database, even if no image has been uploaded.

So, what I need is a simple piece of code that will see if the image in the database actually exists, and if it doesn't, it displays another image that says "no image to display". I am using HTML script to display the image.

ie: if !<img src=classpics/1.jpg>
<img src=classpics/nopic.jpg>

Basically, if the link to the original image is broken, display the nopic.jpg image instead.

Any ideas?


#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 March 2006 - 05:15 PM

More or less, this should point the way ..
if (file_exists($img_url)) {
    echo "<img src='". $img_url. "' border='0' alt=''>";
} else {
    echo "<img src='classic/nopic.jpg'>";

Legend has it that reading the manual never killed anyone.
My site

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users