我正在尝试使用 php 根据项目的 id 显示图像。这是针对电子商务商店的,但是我很难弄清楚。这是我拥有的 php:
<?php
$product_list = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
$productCount = mysql_num_rows($sql);
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$pid = $row['id'];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$product_list .= "HERE IS WHERE THE IMAGE <strong>$product_name</strong> - $$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />";
}
} else {
$product_list = "You have no products listed in your store yet";
}
?>
从理论上讲,我试图添加,文本 HERE IS WHERE THE IMAGE 是要使用的:
<img src='../inventory_images/$pid.jpg' />
然而,我尝试过的这个和其他变体不起作用。图片是怎么上传的,变量“$pid”是商品的id,加上.jpg结尾,下面代码解释一下:
$pid = mysql_insert_id();
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
因此,理论上只需拥有产品 ID,我就可以使用 $pid 来获取图像......这是行不通的。想法?提前致谢!