Hi there i have a problem with my cart calculations in a website i am making and it only displays the last price of the item i add to tthe cart instead of the total of all items added
<?php
$select_cart = mysqli_query($conn, "SELECT * FROM `cart`");
$grand_total = 0;
if(mysqli_num_rows($select_cart) > 0){
while($fetch_cart = mysqli_fetch_assoc($select_cart)){
?>
<tr>
<td><img src="uploaded_img/<?php echo $fetch_cart['image']; ?>" height="100" alt=""></td>
<td><?php echo $fetch_cart['name']; ?></td>
<td>KSH<?php echo number_format($fetch_cart['price']); ?>/-</td>
<td>
<form action="" method="post">
<input type="hidden" name="update_quantity_id" value="<?php echo $fetch_cart['id']; ?>" >
<input type="number" name="update_quantity" min="1" value="<?php echo $fetch_cart['quantity']; ?>" >
<input type="submit" value="update" name="update_update_btn">
</form>
</td>
<td>KSH<?php echo $sub_total = number_format($fetch_cart['price'] * $fetch_cart['quantity']); ?>/-</td>
<td><a href="cart.php?remove=<?php echo $fetch_cart['id']; ?>" onclick="return confirm('remove item from cart?')" class="delete-btn"> <i class="fas fa-trash"></i> remove</a></td>
</tr>
<?php
$grand_total = $sub_total;
};
};
?>