我想先将结果存储在变量中,以便我可以使用它们,但这不会迭代任何东西。请参阅我尝试先将行的值存储在变量中并在表的td中调用它们,但它没有显示任何内容。
是否存在语法错误或其他问题。什么可能是首先存储在变量中的方法?
$query_test = "SELECT itemname, categoryname, manufacturername,
price, shopname,itemurl, itemimage, typename
FROM prices p,
items i,
shops s,
categories c,
manufacturers m,
types t,
modules mo
WHERE p.shopid=s.shopid
AND i.categoryid=c.categoryid
AND p.itemid=i.itemid
AND i.ManufacturerId=m.ManufacturerID
AND i.ModuleId= mo.ModuleID
AND i.TypeId=t.TypeID
AND i.categoryid=1004
AND s.shopid=5003";
$result = mysqli_query($conn, $query_test);
echo "<table border='1'>";
echo "<tr><td>"."Name"."</td>";
echo "<td>"."Category"."</td>";
echo "<td>"."Manufacturer"."</td>";
echo "<td>"."Price"."</td>";
echo "<td>"."Shop"."</td>";
echo "<td>"."Type"."</td>";
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
//output a row here
$name = $row['itemname'];
$category = $row['categoryname'];
$manufacturer = $row['manufacturername'];
$price = $row['price']:
$shop = $row['shopname'];
$type = $row['typename'];
echo "<tr><td>".$name."</td>";
echo "<td>".$category."</td>";
echo "<td>".$manufacturer."</td>";
echo "<td>".$price."</td>";
echo "<td>".$shop."</td>";
echo "<td>".$type."</td></tr>";
/*echo "<tr><td>".($row['itemname'])."</td>";
echo "<td>".($row['categoryname'])."</td>";
echo "<td>".($row['manufacturername'])."</td>";
echo "<td>".($row['price'])."</td>";
echo "<td>".($row['shopname'])."</td>";
echo "<td>".($row['typename'])."</td></tr>";*/
}
echo "</table>";
答案 0 :(得分:1)
在while循环中执行var_dump($row)
,以查看$row
中存储的值。
另外,考虑到你如何访问它们,你应该这样做:
while( $row = mysqli_fetch_assoc($result))