I am using some code and wanted to add a total and display it after the table is displayed. I have tried several places but have not been able to understand the coding to have it I also have the choices to go to other scripts that is also displayed before the tables
Here is the code.
Thanks for any help
jvandal
---------
<?php
session_start();
//connect to database
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mystoredb",$conn) or die(mysql_error());
$display_block = "<h1>Your MatchBrush Shopping Cart</h1>";
//check for cart items based on user session id
$get_cart = "select st.id, si.item_title, si.item_price, st.sel_item_qty, st.sel_item_size, st.sel_item_color from store_shoppertrack as st left join store_items as si on si.id = st.sel_item_id where session_id = '$_COOKIE[PHPSESSID]'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
if (mysql_num_rows($get_cart_res) < 1) {
//print message
$display_block .= "
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>Price</th>
<th>Qty</th>
<th>Total Price</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['item_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);
######## this is the total sttement i have added
$_final_total = $_final_total + $total_price;
$display_block .= "<tr>
<td align=center>$item_title
</td>
<td align=center>$item_size
</td>
<td align=center>$item_color
</td>
<td align=center>\$ $item_price
</td>
<td align=center>$item_qty
</td>
<td align=center>\$ $total_price</td>
<td align=center><a href=\"removefromcart.php?id=$id\">remove</a></td>
</tr>";
} }
#display_block .= " <tr> <td align=center> \ </td></tr>";
####### this is the statement I added to display the grand total
echo (" Total amount for this purchase is $".sprintf("%.02f", $_final_total));
?>
<HTML>
<HEAD>
<TITLE>My Store</TITLE>
</HEAD>
<BODY>
<!--<ahref="next.php?<?php echo(SID); ?>"<Next Page</a> -->
<ahref="next.php?"<Next Page</a>
<hr>
<!--<? echo( session_id()); ?> -->
<?php echo $display_block; ?>
######## this is the transfer statement I have add to
Your entry has been added. Would you like to
add another item?
<Would you like to
Check Out???</p>"
</BODY>
</HTML>