Shopping Cart System in Php
Go to solution
Solved by Hazy125,
how would i make like another box saying "total cost" or something under the the boxes of the amount for a giraffe?
I actually was going to add that in my actual example. But decided not to bother because you should probably be getting that information from a products database. But if you really want to add to the code I already made, you can alter the table code to be
<?php $total = 0; if(!empty($_SESSION['cart'])){ foreach($_SESSION['cart'] as $product){ echo "<tr><td>$product</td><td>"; if($product == "bob"){ echo '$1500'; $total = $total + 1500; }else if($product == "derek"){ echo '$2500'; $total = $total + 2500; }else if($product == "harold"){ echo '$9800'; $total = $total + 9800; }else{ echo '-'; } echo "</td></tr>"; } } echo '<tr><td><strong>TOTAL</strong></td><td>$' . $total . '</td></tr>'; ?>
If you aren't sure still, the live version if you follow that link again has also bee updated
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now