Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Show default image if database is null

Posted on 2012-03-27
Medium Priority
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

Question by:BrighteyesDesign
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 35

Accepted Solution

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

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

Expert Comment

ID: 37771402

Something like that :

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>
	print "No image available";

Open in new window


Author Closing Comment

ID: 37771553
Perfect, thanks!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

604 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