www.webdeveloper.com
Results 1 to 6 of 6

Thread: Problem displaying an image inside a table cell,pls Help!

  1. #1
    Join Date
    Feb 2009
    Posts
    4

    Problem displaying an image inside a table cell,pls Help!

    Hello everyone!

    I have this table :
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <table width="565" height="115" border="1" align="center">
    <tr>
    <td colspan="2" rowspan="4">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
    And a database called "electrical_items" ,with a table called "products" ,with the columns roduct_id,product_brand,product_model,product_price,product_image .

    Now what i want...
    I want to display in the big left cell of the table ,the image stored in a folder named "product_images",but the script to be able to pick the image file name,from the database (i have stored already the image file name in the table "products" already based on the product_id.

    So im looking for a script that its able to read the image file name,based to product_id from the database,then to look for it from the folder "product_images",and then display it in the left cell of the table.

    After that i will use the repeat region to display different products.

    Thank you in advance guys!

  2. #2
    Join Date
    Oct 2007
    Posts
    370
    I think it would be a query like

    Code:
    SELECT product_image FROM products WHERE product_id=$product_id
    assign the value of that search to $product_image


    then PHP code like
    PHP Code:
    <?if ($product_image!='' && file_exists('product_images/'.$product_image) ){echo('<img src="product_images/' .$product_image'">'); }else{echo('Image not available.'); }?>
    In that cell.

    You might want to do more data verification on that filename before you echo it, but that's a start.

  3. #3
    Join Date
    Jun 2008
    Posts
    29
    I would use similar PHP as above but add this line:

    while($row = mysql_fetch_assoc($result))



    For the image in the table, you can just use:

    <img src="images/products/<?php echo $row['image']; ?>" width="100" height="100" alt="<?php echo $row['alt']; ?>">

    Obviously ['image'] can be whatever field you store you images. The ['alt'] is just for SEO, if you have that field in your db.

    Hope this helps.

  4. #4
    Join Date
    Feb 2009
    Posts
    4
    Quote Originally Posted by TecBrat View Post
    I think it would be a query like

    Code:
    SELECT product_image FROM products WHERE product_id=$product_id
    assign the value of that search to $product_image


    then PHP code like
    PHP Code:
    <?if ($product_image!='' && file_exists('product_images/'.$product_image) ){echo('<img src="product_images/' .$product_image'">'); }else{echo('Image not available.'); }?>
    In that cell.

    You might want to do more data verification on that filename before you echo it, but that's a start.
    Im getting an error "Image not available",even though there are photos in the specified folder.

  5. #5
    Join Date
    Feb 2009
    Posts
    4
    anyone?

  6. #6
    Join Date
    Oct 2007
    Posts
    370
    You might try tweaking the path I put in my code by putting a slash in front of it, or even ../ or, if that doesn't work, use a full path, but that's not ideal because the code would cause problems if it were ever used on an SSL page.

    Maybe even the full server path to the webroot and on to the right directory like "/home/user/public_html/product_images"

    You might also place some extra "echo" commands in there to check the values of the variables to make sure they are what you expect them to be.

    I hope this helps.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles