PHP While Loop Summing

Tuesday, November 3, 2015

I am currently making a very standard ecommerce shopping cart, I have set it up so that the items display in the shopping cart looping onto a table from my database.



table class="large-16" style="margin-top: 20px;">
<tr>
<th>Action:</th>
<th>Product:</th>
<th>Price:</th>
<th>Size:</th>
<th>Color:</th>
<th>Quantity:</th>
<th>Price Total:</th>
</tr>



<?php while ($row = mysqli_fetch_array($result)) { ?>
<tr>
<td>
<a href="delete-product-handler.php?id=<?php
echo $row['product_id']; ?>" onclick="return confirm("Are you sure you want to remove this product from your shopping cart?")">
<img src="img/delete.png" alt="delete button">Remove</a>
</td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['product_price']; ?></td>
<td><?php echo $row['product_size']; ?></td>
<td><?php echo $row['product_color']; ?></td>
<td><?php echo $row['product_quantity']; ?></td>
<td><?php $totalItemPrice[] = ($row['product_price'] * $row['product_quantity']);
echo $totalItemPrice; ?></td>

</tr>





As you can see it is set up to add up the Price of each item to the amount of the same item I wish to purchase.



How can I now add up the total of all the summed up prices to get an over all price of everything I am purchasing?

0 comments:

Post a Comment