【发布时间】:2018-05-27 04:08:21
【问题描述】:
我在打印表格时遇到问题。我知道我的 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>";
然后打印所有内容。
在网站上是这样的:
【问题讨论】:
-
还有
print_r($row) -
我们假设它打印
noimage_small.png -
我应该看到这个。您正在访问错误的列。检查您的 sql 查询并将它们与您的 php 匹配
-
你需要哪种类型的输出和你
print里面的行数据while
标签: php html sql mysqli html-table