Results 1 to 2 of 2

Thread: Adding dynamic data

  1. #1
    Join Date
    Nov 2006

    Exclamation Adding dynamic data

    I need to create a grand total for a shopping cart.

    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%>
        <th>Sub Total</th>
        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>
    		$grand_total = sprintf("%.02f", $total_price);
    		$display_block .= "</table><br>
    		Grand Total: $grand_total
    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...

  2. #2
    Join Date
    Dec 2006
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    PHP 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%>
        <th>Sub Total</th>

    $SUM_TOTAL 0;

        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'];

    // Increment sum total
    $SUM_TOTAL += $item_price $item_qty;

    $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>ú 
               <td align=center><a href=\"removefromcart.php?id=
    $grand_total sprintf("%.02f"$SUM_TOTAL);
    $display_block .= "</table><br>
            Grand Total: 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center