地狱社区,我正在尝试建立一个基本上看起来像 excel 表的购物车。布局和主要代码运行良好,但我只能将一行中的产品添加到购物车表中。我的目标是从我想要的行中选择和添加尽可能多的产品。
这是我正在使用的代码:
<?php
$query = "SELECT * FROM products ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div id="product">
<table>
<tr>
<th>Product</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
</tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "shop");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, product, A, B, C, D, E FROM products";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$Id = $row ["id"];
$Product = $row ["product"];
$A = $row ["A"];
$B = $row ["B"];
$C = $row ["C"];
$D = $row ["D"];
$E = $row ["E"];
}
我发现,当我单击“添加到购物车”按钮时,我的代码始终只显示“hidden_price”行中提到的变量的购物车表中的内容。我必须在代码中添加或更改什么才能将其他行(B、C、D...)添加到购物车并能够从我想要的行中选择产品?
预先感谢您的支持!
牧羊人nacy