Jump to content

Increment numer in a while loop


graham23s

Recommended Posts

Hi Guys,

 

i need to incrememnt a digit from 1 to however many items are getting sent to paypal for example:

 

code:

 

<?php
print("<form action=\"https://www.sandbox.paypal.com/cgi-bin/webscr\" method=\"post\" id=\"payPalForm\">\n");
## PAYPAL VARS ## --------------------------------------------------------------------->
print("<input type=\"hidden\" name=\"cmd\" value=\"_cart\">\n");
print("<input type=\"hidden\" name=\"upload\" value=\"1\">\n");
print("<input type=\"hidden\" name=\"business\" value=\"[email protected]\">\n");
print("<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">\n");
## PAYPAL VARS ## --------------------------------------------------------------------->
print("<table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"6\" style=\"border:#d9dce2 1px solid;\">\n");
print("<tr\n>");
print("<td colspan=\"5\" bgcolor=\"#ecedf0\" align=\"left\"><b>Order Details</b></td>\n");
print("</tr>\n");
print("<tr>\n");
print("<td bgcolor=\"#ecedf0\" align=\"center\"><b>Product Name</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Price</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Quantity</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Sum-Total</b></td>\n");
print("</tr>\n");
print("<tr>\n"); 

// while loop the details //
$session_id = $_SESSION['id'];
$queryorder = "SELECT * FROM `fcp_orders` WHERE `customer_id`='$session_id'";
$resultsorder = mysql_query($queryorder);

// loop //
while($row = mysql_fetch_array($resultsorder))
{

$pid = $row['product_id'];
$quantity = $row['quantity'];
$quantity_total = $row['quantity_total'];

// get the name of the product //
$queryproduct = "SELECT * FROM `fcp_products` WHERE `id`='$pid'";
$resultsproduct = mysql_query($queryproduct);
$rows = mysql_fetch_array($resultsproduct);
// the name in a var //
$product_name = $rows['product_name'];
$product_price = $rows['product_price'];

// get the total price due //
$queryprice = "SELECT SUM(quantity_total) as `total` FROM `fcp_orders` WHERE `customer_id`='$session_id'";
$resultsprice = mysql_query($queryprice);
$r = mysql_fetch_array($resultsprice);

// vars //
$total_due = $r['total'];

// shipping //
$shipping_costs = 10;

// total owed //
$total_owed = $total_due + $shipping_costs;

// number format //
$total_owed = number_format($total_owed, 2);

// hidden field with the total //
print("<input type=\"hidden\" name=\"hidden_quantity\" value=\"$total_owed\">");

print("<td align=\"center\">$product_name</td><td align=\"center\">£$product_price</td><td align=\"center\">$quantity</td><td align=\"center\">£$quantity_total</td></tr>\n");
        
for($i = 1; $i <= 1; $i++)
{
print("<input type=\"hidden\" name=\"item_name_$i\" value=\"$product_name\">\n");
print("<input type=\"hidden\" name=\"amount_$i\" value=\"$product_price\">\n");
}
$i++;
    
## PAYPAL VARS ## --------------------------------------------------------------------->

} // end while loop //
?>

 

i have at the minute this:

 

<?php
for($i = 1; $i <= 1; $i++)
{
print("<input type=\"hidden\" name=\"item_name_$i\" value=\"$product_name\">\n");
print("<input type=\"hidden\" name=\"amount_$i\" value=\"$product_price\">\n");
}
$i++;
?>

 

which isn't working it just stays at 1, i really need the $i to increment by 1 then my problems with this are over lol hopefully

 

thanks for any advice

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/93829-increment-numer-in-a-while-loop/
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.