Posted by Karl Irvin on 09/29/54 11:37
I need to loop a shopping carts variables and add each order line to an
array. Following is the code I am using.
The loop works OK but I am only adding the second item ordered to the array.
Can anyone see What I need to change?
<?php
// Items in cart --------------------------------
$num_cart_items = 2;
$item_name1 = "Data Transfer Book";
$quantity1 = 1;
$mc_gross1 = 129.00;
$item_name2 = "Beginning Balance Book";
$quantity2 = 1;
$mc_gross2 = 49.00;
//Begin loop. Use variable variables to loop through cart items --------
for ($i=1; $i<=$num_cart_items; $i++)
{
$tempname = "item_name$i";
$tempquantity = "quantity$i";
$tempgross = "mc_gross$i";
// display each order line - this part works
echo $$tempname . " " .$$tempquantity . " " . $$tempgross . "<br>";
// add each order line to an array - only gets the second (last) cart item
$OrderLines = array($i => array("Item" => $$tempname,
"Qty" => $$tempquantity,
"Extended" => $$tempgross ));
}
[Back to original message]
|