Jump to content

php display loop help


jammer

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.