Results 1 to 2 of 2

Thread: php display images

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default php display images

    Is there a way to tell mysql using php, if there is no data in the database (image.jpg) not to display the emty placeholder in browser where the image should be?

    PHP Code:
    <?php
    // query db
    if (isset($_GET['id'])) {
        
    $sql "SELECT * FROM `products` WHERE id = '" mysql_real_escape_string($_GET['id']) . "'"// from products get id
        
    if ($result mysql_query($sql)) {
          if (
    mysql_num_rows($result)) {

         while (
    $row mysql_fetch_assoc($result)) { //initial the loop

            
    echo "<h4>" $row['name'] . "</h4>"// echo date results as format "h4"
            
    echo "<p>" $row['description'] . "</p>"// echo content as p format "body text"
            
    echo "<h5>Measurements: " $row['measurements'] . "</h5>"// echo content as p format "body text"

    echo "<a href='img/products/{$row['filename']}' rel='lightbox' title='{$row['name']}'>"

    echo 
    "<img src='img/products/thumbnails/{$row['filename']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

    echo 
    "<a href='img/products/{$row['filename2']}' rel='lightbox' title='{$row['name']}'>"

    echo 
    "<img src='img/products/thumbnails/{$row['filename2']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

    echo 
    "<a href='img/products/{$row['filename3']}' rel='lightbox' title='{$row['name']}'>"

    echo 
    "<img src='img/products/thumbnails/{$row['filename3']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

    echo 
    "<a href='img/products/{$row['filename4']}' rel='lightbox' title='{$row['name']}'>"

    echo 
    "<img src='img/products/thumbnails/{$row['filename4']} 'alt='{$row['name']}' title='{$row['name']}' width='156' height='109'></a>";

    }
            } else {
            echo 
    "Something is wrong!";
          }
        }
      }
    ?>
    Many thanks for any help and suggestions.
    Last edited by john0611; 12-04-2009 at 09:15 PM.

  2. #2
    Join Date
    Feb 2008
    Posts
    137
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Default

    PHP Code:
    <?php 
    if (file_exists(img/products/thumbnails/{$row['filename4']}) &&
    isset(
    $row['filename4'])) {
    ... do 
    stuff here
    }
    ?>
    OR
    PHP Code:
    <?php 
    if (file_exists(img/products/thumbnails/{$row['filename4']}) &&
    isset(
    $row['filename4'])) {
    ... do 
    stuff here...
    }else{ 
    ... do 
    oppstuff here...
    }
    ?>
    ASCII stupid question, get a stupid ANSI!
    Beta is Latin for still doesn’t work.
    Mac users swear by their Mac, PC users swear at their PC.
    Keyboard not found...Press any key to continue.

Bookmarks

Posting Permissions

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