Reply to Adding cart variables to an array

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация