【问题标题】:Unable to display different images from the database无法显示来自数据库的不同图像
【发布时间】:2017-06-27 11:05:42
【问题描述】:

我正在开发一个电子商务网站,但我无法在我的主页上显示来自数据库的不同产品图像。 下面的代码只显示所有产品的一张图片,而它们应该是不同的图片(通过后端上传)。 产品名称、价格和类别显示得很好,但图像却没有。我想知道为什么。

这是我的代码

<?php
// connect to the database
include('variables.php');

// get the records from the database
$sql = "SELECT * FROM products ORDER BY id ASC LIMIT 0, 6";
$result = $connection->query($sql);
$getImage=mysqli_query($connection, "SELECT * FROM products ") or die("Could not retrieve image: " .mysqli_error($connection));
$path=mysqli_fetch_assoc($getImage) or die("Could not fetch array : " .mysqli_error($connection));
if ($result) 
{
    // output data of each row                    
    while($row = $result->fetch_assoc()) 
    {  
        echo '<li class="span3"><div class="product-box">';

        echo'<span class="sale_tag"></span>';

        echo'<p><a href="product_detail.php?id=' . $row["id"] . '"><img src="../backend/images/'.$path['productimage'].'" width="250" height="120"></a></p>';           
        echo  $row["name"]. "</a><br>";
        echo'<a href="products.html" class="category">' . $row["categoryname"]. '</a>';
        echo'<p class="price">KSh:' . $row["price"].'</p>';
        echo'</div></li>';
    }
}
?>

请帮忙

【问题讨论】:

    标签: php html mysql sql


    【解决方案1】:

    在while循环中将$path改为$row

    【讨论】:

    • 非常感谢。有用。我能再问你一个问题吗? :)
    • 不客气 :)。如果它相关你可以在这里问,否则最好发布另一个
    • 好的。那我贴一下吧。谢谢
    猜你喜欢
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    相关资源
    最近更新 更多