RE: [PHP] Array in a Loop Question
| From: | Jeff Hatcher | Date: | Tue, 26 Mar 2002 19:12:49 +0000 |
| Subject: | RE: [PHP] Array in a Loop Question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-90251@lists.php.net to get a copy of this message | ||
for ($i=0;$i<$_POST[count];$i++)
{
echo $_POST['address' . $i] . '<br>';
}
Concanate array key 'address' with $i
This works fine and I also can do the address[] but my ultimate result
is to put this in the database.
So address='$_POST['address' . $i]' fails and
address='$_POST[address][$i]' fails.
I can reassign the values to new variables i.e. $address =
$_POST['address' . $i]; DB Update address='$address'
Or
$address $_POST[address][$i]; DB Update address='$address'
So my question is how can I put this in the database without having to
reassign my variable name?
Current Solution:
case "process1":
for ($i=0;$i<$_POST[count];$i++)
{
$postal=$_POST[postal1][$i] . " " .
$_POST[postal2][$i];
$state=$_POST[state][$i];
$address=$_POST[address][$i];
$email=$_POST[email][$i];
$city=$_POST[city][$i];
$customerid=$_POST[customerid][$i];
mssql_query("UPDATE customer SET
postal='$postal',state='$state',address='$address',email=$_POST['email'
. $i],city='$city' WHERE id='$customerid'") or die("DATABASE ERROR:
updating customer, residentchange process 1");
}