How to display images in PHP code

Discussion in 'PHP' started by lenhhoxung, Dec 27, 2009.

  1. #1
    Dear all brothers and sisters,

    I had a folder which stored the pictures. Now I want to display them on the screen with PHP code by SQL
    For example

    SELECT product_name, product_price, product_image from product;

    How can I display product_image filed

    Help me ????

    Thks very much

    Sam
     
    lenhhoxung, Dec 27, 2009 IP
  2. ibg

    ibg Member

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #2
    What does the product_image field contain? How are the images stored in the folder (by product name)?
     
    ibg, Dec 28, 2009 IP
  3. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just a text paragraph, images/resized/Castrol_Magnatec_4a6836463a23f_150x150.jpg

    Thks friends.
     
    lenhhoxung, Dec 28, 2009 IP
  4. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    try something along the line of
    echo "<img src=$row[2] />"
    Code (markup):
     
    javaongsan, Dec 28, 2009 IP
  5. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It does not work. Here is my code

    $result = mysql_query("SELECT * FROM product");// and (channel=($age)");

    echo "<table border='1'>
    <tr>
    <th>Nhãn hàng</th>
    <th>Sản phẩm</th>
    <th>Khuyến mãi</th>
    <th>Ghi chú</th>
    </tr>";

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['brand_name'] . "</td>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "<td>" . <img src=$row['product_image'] />. "</td>";//<img src=$row[2] />
    echo "<td>" . $row['ghichu'] . "</td>";
    echo "</tr>";
    }

    echo
     
    lenhhoxung, Dec 28, 2009 IP
  6. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Parse error: syntax error, unexpected '<' in /var/www/web29/web/sanpham/index.php on line 120
     
    lenhhoxung, Dec 28, 2009 IP
  7. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    please help me, brothers
     
    lenhhoxung, Dec 28, 2009 IP
  8. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #8
    Try this

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['brand_name'] . "</td>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "<td><img src='".$row['product_image']."' /></td>";
    echo "<td>" . $row['ghichu'] . "</td>";
    echo "</tr>";
    }
     
    HuggyStudios, Dec 28, 2009 IP
  9. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #9
    whats the output of product_image?

    TE=lenhhoxung;13235856]It does not work. Here is my code

    $result = mysql_query("SELECT * FROM product");// and (channel=($age)");

    echo "<table border='1'>
    <tr>
    <th>Nhãn hàng</th>
    <th>Sản phẩm</th>
    <th>Khuyến mãi</th>
    <th>Ghi chú</th>
    </tr>";

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['brand_name'] . "</td>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "<td>" . <img src=$row['product_image'] />. "</td>";//<img src=$row[2] />
    echo "<td>" . $row['ghichu'] . "</td>";
    echo "</tr>";
    }

    echo[/QUOTE]
     
    javaongsan, Dec 28, 2009 IP
  10. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks all, I did it

    Sam
     
    lenhhoxung, Dec 28, 2009 IP
  11. swiftnomad

    swiftnomad Active Member

    Messages:
    185
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    50
    #11
    next time you should ( when you ask for help ) post the full code of the page to pastie.org and we can help you faster by just editing it from there. :) I know I had nothing to do with this process because I just found the thread however, when I say 'we' I mean 'other programmers'.
     
    swiftnomad, Dec 28, 2009 IP