Jump to content

Anybody know loops?


Schlo_50

Recommended Posts

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

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.