我在打印表格时遇到问题。我知道我的 SQL 查询有效,但我的网站上没有显示任何内容。我对 PHP 和 SQL 有点陌生,现在我被困住了。非常感谢有关我的代码的任何提示!
$setidquery = "SELECT
inventory.quantity,
inventory.itemid,
inventory.colorid,
parts.partname,
sets.setid,
inventory.itemtypeid
FROM
inventory
join
parts
on inventory.itemid = parts.partid
join
colors
on inventory.colorid = colors.colorid
join
sets
on inventory.SetID = sets.SetID
where
sets.setid = '$_COOKIE[setid]'
order by
partname asc
limit 1000";
我在这里尝试获取正确的图像。
echo "<table class=\"table\">";
echo "<tr><th>Quantity:</th><th>Partname:</th><th>ItemID:</th><th>SetID</th><th>Image:</th></tr>";
while($row = mysqli_fetch_array($result)){
$prefix = "http://www.itn.liu.se/~stegu76/img.bricklink.com/";
$Quantity = $row['Quantity'];
$ItemID = $row['ItemID'];
$ColorID = $row['ColorID'];
$ItemtypeID = $row['ItemtypeID'];
$imagesearch = mysqli_query($conn, "SELECT * FROM `images` WHERE ItemTypeID = '$ItemtypeID' AND ItemID = '$ItemID' AND ColorID = '$ColorID' ");
$imageinfo = mysqli_fetch_array($imagesearch);
if($imageinfo['has_jpg']) {
$filename = "$ItemtypeID/$ColorID/$ItemID.jpg";
} else if($imageinfo['has_gif']) {
$filename = "$ItemtypeID/$ColorID/$ItemID.gif";
} else {
$filename = "noimage_small.png";
}
$SetID = $row['SetID'];
$Partname = $row['Partname'];
echo "<tr>
<td>$Quantity</td>
<td>$Partname</td>
<td>$ItemID</td>
<td>$SetID</td>
<td><img src=\"$prefix$filename\" alt=\"Part $ItemID\"/></td>
</tr>";
}
echo "</table>";
然后打印所有内容。
在网站上它看起来像这样:
最佳答案
在 PHP 中,变量 和数组键 区分大小写。
您正在从 SQL 获取 itemid
并使用 ItemID
访问它。
所以,$row['ItemID']
不同于 $item['itemid']
这就是您没有显示图像的原因。
因此,更正以下内容:
$Quantity = $row['Quantity'];
$ItemID = $row['ItemID'];
$ColorID = $row['ColorID'];
收件人:
$Quantity = $row['quantity'];
$ItemID = $row['itemid'];
$ColorID = $row['colorid'];
关于php - SQL打印表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47790136/