iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-17-2008, 03:50 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Question How to show default picture?

Hi

I am wondering if anyone knows how I can display a default photo if the picture is not found in the database while extracting. The default photo is located in a different folder.
Example: domain.com/images/default.jpg

Here is my code:

Code:
<?php

$query1="SELECT `item`,`picture`,`code` FROM `Gallery` where `active` ='1' order by `item` DESC LIMIT 5";
$result1 = mysql_query($query1);

$num_rows = mysql_num_rows($result1);
for($i = 0; $i < $num_rows; $i++) {
    $row = mysql_fetch_array($result1);
 $product=mysql_result($result1,$i,"item");
 $photoid=mysql_result($result1,$i,"picture");
 $ext=mysql_result($result1,$i,"code");

echo "Product: <img src='$siteurl/photo/$photoid.$ext'><a href='$siteurl/$product.html'><font color=Red>$product</font></a><br />
";
}
?>
Currently if the picture exists, it will display them but when the picture is non existence, it will not display (show as missing image). So, instead of not displaying, I am thinking of showing the default photo instead.

How can I do that? Any help is greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 12-17-2008, 09:28 AM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: How to show default picture?

Code:
<?php

$query1="SELECT `item`,`picture`,`code` FROM `Gallery` where `active` ='1' order by `item` DESC LIMIT 5";
$result1 = mysql_query($query1);

$num_rows = mysql_num_rows($result1);
for($i = 0; $i < $num_rows; $i++) {
 $row = mysql_fetch_array($result1);
 $product=mysql_result($result1,$i,"item");
 $photoid=mysql_result($result1,$i,"picture");
 $ext=mysql_result($result1,$i,"code");

 if (file_exists('$siteurl/photo/$photoid.$ext')) {
   echo "Product: <img src='$siteurl/photo/$photoid.$ext'><a href='$siteurl/$product.html'><font color=Red>$product</font></a><br />";
 } else {
   echo "Product: <img src='$siteurl/nophoto/emptypic.jpg'><a href='$siteurl/$product.html'><font color=Red>$product</font></a><br />";
 }
}
?>
__________________
Dynamic Software Development
www.activeminds.ca

Last edited by DaveSawers; 12-17-2008 at 09:31 AM.
Reply With Quote
  #3 (permalink)  
Old 12-18-2008, 03:40 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Question Re: How to show default picture?

Hi DaveSawers

Tried your solution but it simply shows emptypic.jpg for all even though there are 2 other photos.

The 'code' is actually extension code for photos - i.e. jpg, gif or png. If no photo then the 'code' will be NULL.

Any method to use the 'code' for NULL to display the emptypic.jpg instead?

Thanks!
Reply With Quote
  #4 (permalink)  
Old 12-20-2008, 05:18 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Question Re: How to show default picture?

Code:
 if (file_exists('$siteurl/photo/$photoid.$ext')) {
   echo "Product: <img src='$siteurl/photo/$photoid.$ext'><a href='$siteurl/$product.html'><font color=Red>$product</font></a><br />";
Seems like this code does not check for the photo existence as it simply shown the emptypic.jpg instead even though there is a photo.
Code:
 } else {
   echo "Product: <img src='$siteurl/nophoto/emptypic.jpg'><a href='$siteurl/$product.html'><font color=Red>$product</font></a><br />";
 }
Anyway to ensure that file exist command really check for the existence before jumping into the else command to show the default photo?

Any suggestion is greatly appreciated.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Picture from Cratima - I do have a picture! Cratima Member Photos 3 07-31-2006 03:31 AM
PR 5 - flash slide show and photo slide show related lookaa Link Exchange 2 03-22-2006 08:16 AM
IIS 5.0 and default log properties ADAM Web Design IT Discussion Forum 2 11-07-2005 11:28 AM
Replace MSN as default on my pc Rats MSN Search Discussion Forum 5 11-13-2004 07:09 AM
Only want picture to show at night. wbsweb Graphics & Design Discussion Forum 9 11-09-2003 12:15 AM


All times are GMT -4. The time now is 07:24 AM.



Search Engine Optimization by vBSEO 3.3.0