jammer Posted April 13, 2008 Share Posted April 13, 2008 hello i am trying to display items in a shopping cart but i am totally stumped for a certain part any help would be appreciated <?php //creates initial cart if(!isset($_SESSION['cart'])) $_SESSION['cart'] = array($_SESSION['id'] => $param["quantity"]); //this will overwrite the quantity if item exists in cart $_SESSION['cart'][$_SESSION['id']] = $param["quantity"]; //display the cart <? for($i=0; $i<count($_SESSION['cart']); $i++){ $items = Product::find(key($_SESSION['cart'])); ?><tr><? ?><td><?= $items['description']; ?></td><? ?><td><?= $_SESSION['cart'][$_SESSION['id']] ?></td><? ?><td><?= $items['price'] ?></td><? next($_SESSION['cart']); ?><tr><? } ?> ?> The $items finds the specific price and description for each item in the cart the problem is displaying the quantity <?= $_SESSION['cart'][$_SESSION['id']] ?> will only display the most recent quantity. I think i need another loop but not sure Link to comment https://forums.phpfreaks.com/topic/100936-php-display-loop-help/ Share on other sites More sharing options...
BlueSkyIS Posted April 13, 2008 Share Posted April 13, 2008 there is no need to reference $_SESSION['id']. it is known and assumed. use a different key on you $_SESSION['cart'] array to identify each product and it's quantity, maybe SKU? Link to comment https://forums.phpfreaks.com/topic/100936-php-display-loop-help/#findComment-516176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.