我正在尝试为我的Web应用程序构建购物车

时间:2019-09-28 17:53:14

标签: php html css mysqli cart

我正在尝试为我的业务应用程序创建购物车,我已经编写了这段代码,它不会给我任何错误,但是不会检索数据库中的数据

cart.php看起来像这样

$last_id = mysqli_insert_id($con);
$_SESSION['last_id'] = $last_id;
$sql = "SELECT * FROM product_order WHERE ord_id = '$last_id'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);

我创建了一个表格来显示数据

<tr>
                        <th width="5%">Last Id</th>
                        <th width="5%">Order id</th>
                        <th width="5%">Selected Card</th>
                        <th width="15%">Field 1</th>
                        <th width="15%">Field 2</th>
                        <th width="15%">Field 3</th>
                        <th width="15%">Field 4</th>
                        <th width="15%">Field 5</th>
                        <th width="5%">Quantity</th>
                        <th width="5%">Price</th>
                        <th width="5%">Total</th>
                        <th width="15%">Action</th>
                    </tr>
                    <tr>
                    <td><?php echo $last_id?></td>
                    <td><?php echo $row['ord_id']?></td>
                    <td><?php echo $row['card_id']; ?></td>
                    <td><?php echo $row['field1']; ?></td>
                    <td><?php echo $row['field2']; ?></td>
                    <td><?php echo $row['field3']; ?></td>
                    <td><?php echo $row['field4']; ?></td>
                    <td><?php echo $row['field5']; ?></td>
                    <td><?php echo $row['quantity']; ?></td>
                    <td><?php echo $row['price']; ?></td>
                    <td><?php echo $total ?></td>

1 个答案:

答案 0 :(得分:-1)

尝试以下语法:

$sql = "SELECT * FROM product_order WHERE ord_id =" . $last_id;

  <?php foreach ($row as $r) : ?>
  <td><?php echo $r['ord_id']?></td>
  <td><?php echo $r['card_id']; ?></td>
  <td><?php echo $r['field1']; ?></td>
  <td><?php echo $r['field2']; ?></td>
  <td><?php echo $r['field3']; ?></td>
  <td><?php echo $r['field4']; ?></td>
  <td><?php echo $r['field5']; ?></td>
  <td><?php echo $r['quantity']; ?></td>
  <td><?php echo $r['price']; ?></td>
  <?php endforeach; ?>