我为我妻子的珠宝网站创建了一个数据库。当我试图从数据库中收集产品页面的信息时,我只能获得我放入数据库中的最后一项。我最初是从一个教程中获得代码的,为了获得任何项目,我必须在它上面工作。基本上,我需要访问所有的产品,但我只有一个。有人能告诉我我错过了什么吗?
调出这些项目的代码:
$id = '';
if( isset( $_GET['id'])) {
$id = $_GET['id'];
}
$sql = "SELECT * FROM products WHERE category = 'Accessories'";
$result = mysqli_query($con, $sql);
$resultCheck = mysqli_num_rows($result);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $item_number = $row["item_number"];
$price = $row["price"];
$desc = $row["description"];
$category = $row["category"];
}
}下面是表格的代码:
<table width="100%" border="2" cellspacing="0" cellpadding="15">
<tr>
<td width="19%" valign="top"><img src="pictures/inventory/<?php echo $pid; ?>.jpg" width="142" height="188" alt="<?php echo $item_number; ?>" /><br />
<a href="pictures/inventory/<?php echo $pid; ?>.pngjpg">View Full Size Image</a>
</td>
<td width="81%" valign="top">
<h3 class="Item"><?php echo $item_number; ?></h3>
<p>
<?php echo "$".$price; ?>
<br />
<br />
<?php echo $desc; ?>
<br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $pid; ?>" />
<input class="button" type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
</table>https://stackoverflow.com/questions/52152997
复制相似问题