Submit Your Article Forum Rules

Results 1 to 4 of 4

Thread: How to show default picture?

  1. #1
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    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.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  2. #2
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760

    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

  3. #3
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    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!
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  4. #4
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    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.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •