huntrguy102 Posted April 28, 2010 Share Posted April 28, 2010 I have this code function showCart5() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM books WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $total += $price * $qty; $output[] = '<strong> $'.$total.'</strong>'; } } else { $output[] = ' '; } return join('',$output); } which is basically posting the final price. I am working on a book store and when someone puts in more than 1 different book. it posts the price of the first book and then the total price of both books. I think its a problem with the foreach part of the function. Is there a way I can replace the foreach with something else that will just post the final total? here is the link to the bookstore http://www.chulainnlibros.com/cart/index.php . If you try it your self you may have any idea of what I'm talking about. Link to comment https://forums.phpfreaks.com/topic/200067-is-there-something-i-can-replace-foreach-with/ Share on other sites More sharing options...
fenway Posted April 28, 2010 Share Posted April 28, 2010 Huh? Link to comment https://forums.phpfreaks.com/topic/200067-is-there-something-i-can-replace-foreach-with/#findComment-1050142 Share on other sites More sharing options...
huntrguy102 Posted April 30, 2010 Author Share Posted April 30, 2010 never mind..... Link to comment https://forums.phpfreaks.com/topic/200067-is-there-something-i-can-replace-foreach-with/#findComment-1051085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.