【发布时间】: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>';
}
}
?>
请帮忙
【问题讨论】: