Solved

Show default image if database is null

Posted on 2012-03-27
3
336 Views
Last Modified: 2012-03-27
I have a product website where my client uploads details ie name, image etc.

If no image is uploaded (which means no filepath entry in the 'image' column of the database) I want to display a generic 'No image available' image. How would I do this?

Here's the code which displays the image...

<a href="detail.php?id=<?php echo $row_product['id']; ?>"><img src="uploads/thumb_<?php echo $row_product['image']; ?>" alt="" border="0" /></a>

Open in new window

0
Comment
Question by:BrighteyesDesign
3 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 37771398
<a href="detail.php?id=<?php echo $row_product['id']; ?>"><?php
if($row_product['image'])
{
  echo '<img src="uploads/thumb_' . $row_product['image'] . '" alt="" border="0" />';
}
else
{
  echo '<img src="http://thegarageblog.com/garage/wp-content/uploads/noimageavailable.jpg" alt="" border="0" />';
}
?></a>

Just replace http://thegarageblog.com/garage/wp-content/uploads/noimageavailable.jpg with the correct URL to your own "no image available" image.
0
 
LVL 10

Expert Comment

by:MadShiva
ID: 37771402
Dear,

Something like that :

<?php
if (empty($row_product['image'])) 
{
?>
<a href="detail.php?id=<?php echo $row_product['id']; ?>"><img src="uploads/thumb_<?php echo $row_product['image']; ?>" alt="" border="0" /></a>
<?php
}
else
	{
	print "No image available";
	}
?>

Open in new window


Regards
0
 

Author Closing Comment

by:BrighteyesDesign
ID: 37771553
Perfect, thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now