Help with a foreach statement
| From: | Ron Piggott | Date: | Sun, 11 May 2008 18:54:00 +0000 |
| Subject: | Help with a foreach statement | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-274154@lists.php.net to get a copy of this message | ||
I am writing a shopping cart.
Products assigned in the following fashion:
$_SESSION['selection'][$product]=$quantity;
I am wanting to display the list of products in the shopping cart in a
list for the user to see as they continue shopping.
I put the SESSION variable into $cart
$cart = $_SESSION['selection'];
then I start the foreach and this is where I get messed up. I am trying
to ECHO the following syntax to the screen with each selected product:
The part I need help with is to write the foreach loop to give me
$product (so I may query the database to find out the product name) and
the $quantity (so I may show the user what they are purchasing). The
part that is messing me up is that this is an array.
My ECHO statement should look like this:
echo "<li><a href=\"" . $path_to_shopping_cart . "product/" .
$cart[$product_id] . "/\">" . $product_name . "</a> - " .
$quantity .
"</li>\r\n";