如何獲得購物車的總量並將其放置在桌子下面的總量?我應該使用JavaScript還是隻使用PHP?請給我一些建議。謝謝。如何獲取表格上的總行數?
<thead>
<tr>
<th class="text-center">Product ID</th>
<th class="text-center">Product Name</th>
<th class="text-center">Description</th>
<th class="text-center">Quantity</th>
<th class="text-center">Price per Unit</th>
<th class="text-center">Total Amount</th>
</tr>
</thead>
<tbody>
<?php
$selectCart = "SELECT * FROM cart INNER JOIN products ON products.product_id = cart.product_id";
$execSelectCart = mysqli_query($connection, $selectCart);
while ($row = mysqli_fetch_array($execSelectCart)) {
$cartProId = $row['product_id'];
$cartProName = $row['product_name'];
$cartProDesc = $row['description'];
$cartSellPrice = $row['sell_price'];
$cartQty = $row['quantityCart'];
$compute = $cartSellPrice * $cartQty;
$totalAmount = number_format((float)$compute, 2, '.', '');
?>
<tr>
<td class="text-center"><?php echo $cartProId; ?></td>
<td class="text-center"><?php echo $cartProName; ?></td>
<td class="text-center"><?php echo $cartProDesc; ?></td>
<td class="text-center"><?php echo $cartQty; ?></td>
<td class="text-center"><?php echo $cartSellPrice; ?></td>
<td class="text-center"><?php echo $totalAmount ?></td>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<hr>
<div class="row text-right">
<div class="col-xs-2 col-xs-offset-8">
<p>
<strong>
Sub Total : <br>
VAT 12% : <br>
Total : <br>
</strong>
</p>
</div>
<div class="col-xs-2">
<strong>
$36.00 <br>
N/A <br>
<?php echo $totalAmount; ?> <br>
</strong>
</div>
</div>
</div>
這是我的桌子。你可以看到,當我在while循環之外回顯$totalamount
時,它只能得到最後一行。