Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change of image

Status
Not open for further replies.

edanlee

Technical User
May 21, 2005
4
US
ok so i have a database of contacts so a company can add and remove information from the contact list. we decided to do a image of each person. i made a image that is a placeholder if the image field is empty but i'm having trouble setting it up now. heres what i have:

<img src="<?php echo $row_contacts['image']; ?>" width="128" height="128">

that is the code to get the image from the image field in mysql. how can i code that to do like a if image field is empty then display this image <img src="/images/noimage.jpg" width="128" height="128">

thanks for the help...hopefully,
Edanlee
 
Code:
<img src="<?php if ($row_contacts['image']) { echo $row_contacts['image']; } else { echo '/images/noimage.jpg'; } ?>" width="128" height="128">

M. Brooks
 
Would it not be easier to just default the field in the database to the noimage path.

That way there is no checking involved. If it has an image it shows the image, otherwise it shows the noimage.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yep, I'd agree with Vacunita, you shouldn't be doing this in the code if its somthing the database can handle itself.

Just use the 'defult' value in the image field to list that url.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top