I need to create a grand total for a shopping cart.
The above code gets data from the database and calculates the prices to create a sub total. Im now trying to add this random number of prices togeather to create the grand total but struggling. I need to add the total from each row and dont really no how. Any info or tutorials would be much appreciated...HTML Code:if (mysql_num_rows($get_cart_res) < 1) { //print message $display_block .= "<P>You have no items in your cart. Please <a href=\"seestore.php\">continue to shop</a>!</p>"; } else { //get info and build cart display $display_block .= " <table celpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>Title</th> <th>Size</th> <th>Color</th> <th>Qty</th> <th>Sub Total</th> <th>Action</th> </tr>"; while ($cart = mysql_fetch_array($get_cart_res)) { $id = $cart['id']; $item_title = stripslashes($cart['item_title']); $item_price = $cart['sel_item_size']['price']; $item_qty = $cart['sel_item_qty']; $item_color = $cart['sel_item_color']; $item_size = $cart['sel_item_size']; $total_price = sprintf("%.02f", $item_price * $item_qty); $display_block .= "<tr> <td align=center>$item_title <br></td> <td align=center>$item_size <br></td> <td align=center>$item_color <br></td> <td align=center>$item_qty <br></td> <td align=center>£ $total_price</td> <td align=center><a href=\"removefromcart.php?id=$id\">remove</a></td> </tr>"; } $grand_total = sprintf("%.02f", $total_price); $display_block .= "</table><br> Grand Total: $grand_total


Reply With Quote
Bookmarks