Schlo_50 Posted March 20, 2008 Share Posted March 20, 2008 I am using a php shopping cart and would like to upload the entire contents of the cart to Paypal when the user is ready to checkout, including the individual item title/description and price. However, I don't want to have to hard code the items and amounts, but would prefer to have a loop that runs for the item_name and amount incrementing the names (item_name_x and amount_x) and passing in the values using my variables ($item_title and $item_price). If I have $item as the variable for individual items put in the shopping cart and $price as the variable for their prices. Does anybody have any help for me please? Im just not sure how to loop and increment the form names together. $numberOfItems = 1; for ($i = 1; $i<=$numberOfItems; $i++) { $z = "item_name_".$i.""; $y = "amount_".$i.""; print("<input type=\"hidden\" name=\"item_number\" value=\"{$i}\">\n"); print "<input type=\"hidden\" name=\"$z\" value=\"$item\">"; print "<input type=\"hidden\" name=\"$y\" value=\"$price\">"; } Help! Please? Link to comment https://forums.phpfreaks.com/topic/97054-anybody-know-loops/ Share on other sites More sharing options...
huhn_m Posted March 20, 2008 Share Posted March 20, 2008 my suggestion would be to use arrays. They are way easier than what you try to do. Link to comment https://forums.phpfreaks.com/topic/97054-anybody-know-loops/#findComment-496625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.