THIS IS MY CODE FOR MY CHECKOUT SCRIPT, IM TRYIN TO ADD ALL THE QUANTITY TOGETHER AND ALL THE PRICE TOGETHER AND GET IT TO DISPLAY IN THE TOTAL QUANTITY FIELD AND TOTAL PRICE FIELD, BUT I DONT THINK IM USING THE COUNT ELEMENT RIGHT. I'VE HAD A GO BUT I DONT KNOW WHATS HAPPEN COZ IT NOT DOING ANYTHING. I DON'T THINK I'VE PUT IN THE RIGHT WAY. PLS HELP, IM VERY NEW TO PHP. I'VE HIGHLIGHT MY PROBLEM AREA IN RED. <?php session_start(); ?> <?=$_SESSION['customer_id']?></p>[/url] <?php if (isset ($_SESSION['cart'])){ ?> <body> <center> <h1><img src="logo.jpg" align=center width="400" height="110"></h1> </center> <font face="scans-serif" color="Purple" size="5" align="right" >Order</font> <p><?php $usr = $_SESSION['email']; echo $usr;?>logged In</p> <p>Please Check your order</p> <table width="30%" border="1" bgcolor=""> <tr> <th width="5%"> STYLE NUMBER</th> <th width="6%"> DETAILS</th> <th width="6%"> QUANTITY</th> <th width="7%"> SIZE </th> <th width="7%"> PRICE </th> <?php foreach ($_SESSION['cart'] as $key => $general_cartoon) { ?> <tr> <td><?php echo $_SESSION['cart'][$key] ['cartoon_id']; ?></td> <td><?php echo $_SESSION['cart'][$key] ['title']; ?></td> <td><?php echo $_SESSION['cart'][$key] ['quantity'];?></td> <td><?php echo $_SESSION['cart'][$key] ['size'];?></td> <td><?php echo $_SESSION['cart'][$key] ['price'];?></td> <?php $quantity =$_SESSION['cart'][$key]['quantity'];?> <td> <tr> <td><?php $total_quantity = count($quantity); ?></td> <td><?php $total_order_of_order = count($price); ?></td> </tr> <tr> <?php } ?> <tr></tr> <td></td> <td>Total Quantity</td> <td> <?php echo $total_quantity ?> </td> <td></td> <tr></tr> <td></td> <td>Total Price</td> <td><?php echo $total_cost_of_order ?></td> </tr> </table> <p> To proceed to checkout press</p> <td><a href="rmcheckoutform.php">Continue[/url] </td> <?php } else { ?> NOTHING IN YOUR CART <?php } ?> <p> For any amendments please return to your shopping cart</p> <a href="shoppingcart.php">Shopping Cart[/url] </body> </html>
I am not sure how your cart is stored and if the price already reflects the price * quantity. I think this might work. <?php foreach ($_SESSION['cart'] as $key => $general_cartoon) { ?> <tr> <td><?php echo $_SESSION['cart'][$key] ['cartoon_id']; ?></td> <td><?php echo $_SESSION['cart'][$key] ['title']; ?></td> <td><?php echo $_SESSION['cart'][$key] ['quantity'];?></td> <td><?php echo $_SESSION['cart'][$key] ['size'];?></td> <td><?php echo $_SESSION['cart'][$key] ['price'];?></td> <?php $quantity =$_SESSION['cart'][$key]['quantity']; $price=$_SESSION['cart'][$key]['price']*$quantity; ?> <td> <tr> <td><?php $total_quantity +=$quantity; ?></td> <td><?php $total_order_of_order+=$price; ?></td> </tr> <tr> <?php } ?> PHP: