shopping cart - PHP While Loop Summing -


i making standard ecommerce shopping cart, have set items display in shopping cart looping onto table 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 sure want remove product 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 can see set add price of each item amount of same item wish purchase.

how can add total of summed prices on price of purchasing?

declare array before while.

$totalitemprice = array(); 

and can use array_sum:

echo array_sum($totalitemprice); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -