请花时间研究准备好的报表。PDO将使你免于头痛。此外,MySQLi>MySQL。
$sql = $pdo->prepare("SELECT * FROM `products` WHERE `id` = :item_id ORDER BY `id`");
$sql->bindValue(":item_id", $item_id, PDO::PARAM_INT);
if ($sql->execute()) {
foreach ($sql->fetchAll(PDO::FETCH_ASSOC) as $row) {
$product_name = $row["product_name"];
for ($i = 1; $i <= $row['quantity']; $i++) {
$cartOutput .= "<tr>";
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
$cartOutput .= '</tr>';
}
}
}