Message-Id: <[EMAIL PROTECTED]>
From: "Chris Payne" <[EMAIL PROTECTED]>
To: <php-db@lists.php.net>
Date: Wed, 25 May 2005 00:53:59 -0400
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0000_01C560C4.3CC5A710"
Subject: Form information
Hi there everyone,
I'm pulling data from my MySQL DB with PHP 4.2, and I have a quantity box
for multiple items, what I'm not sure of is this:
BTW, I use quantity[] as the name in the form, so it's an array, I just need
to know how to add an extra item called productid to it so I can carry that
info over too :-)
Just set each text field to have a name and ID like this : assume your
product IDs are numbered 21-28 (to avoid confusion)
for ($product_id=21; $product_id<28; $product_id++) {
print('<input type="text" name="quantity[<?=$product_id?>]"
name="quantity_<?=$product_id?>" value="" />');
}
So each element of the POST array called quantity now has a numeric index,
rather than the default array index of 0,1,2,3,4 which you'd get back from
the browser, you now get back an array like this (assuming quantities of
10506, 45000, 550, 1000 and so on)
quantity [21]=10506, [22]=45000, [23]=550, [24]=1000, ......
And when you get that quantity as an array from your POST variables, just
loop through it :
foreach ($_POST["quantity"] as $product_id=>$amount) {
print("Product ID : ".$product_id." Amount : ".$amount);
}
Do whatever you intend to do with the database, instead of the print statement
Cheers - Neil
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php