Forum Moderators: coopster
It writes like this:
while
blah blah blah..echo "$product - Qty: <input type=\"text\" name=\"qty\" size=2><br>";
My question:
How do I assign ascending numbers to each "qty" field?
I'd like the output to be:
product 1 : <input type=\"text\" name=\"qty1\" size=2><br>
product 2 : <input type=\"text\" name=\"qty2\" size=2><br>
product 3 : <input type=\"text\" name=\"qty3\" size=2><br>
and so on..
the products part is already working, I'm just after how to number the "qty" field for each.
Thanks in advance.
mc
create a variable before the while loop:
$qtyvalue = 0;
then increment the value with each iteration of the loop:
$qtyvalue ++;
then add the variable to the field name:
product X : <input type=\"text\" name=\"qty\".$qtyvalue.\"\" size=2><br>
there is probably a better way, there are plenty of PHP pros round here ;o)
HTH
dazz
echo "$product - Qty: <input type=\"text\" name=\"qty[".$productid."]\" size=2><br>";
You should ensure that $productid is the id number of the product, or catalog number.
In this way the results after posting the form will be in an array $_POST[qty], and to find the quantity for product 1234, you will just do $_POST[qty][1234], paving the way toward:
pg/mysql_query("UPDATE products SET qty = ".intval($_POST[qty][$id])." WHERE productid = $id");