Re: array insert help
| From: | Ernest E Vogelsinger | Date: | Sat, 22 Mar 2003 21:04:50 +0000 |
| Subject: | Re: array insert help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140711@lists.php.net to get a copy of this message | ||
At 20:59 22.03.2003, Jason Dulberg said:
--------------------[snip]--------------------
>My problem is that I'm not sure how to set up the array for the fields and
>how to take the input fields and insert them. Do I need a multidimensional
>array for this?
>
>ie.
><input type="text" name="address[address][]">
><input type="text" name="address[city][]">
>
>How would I decode that to create an insert statement??
--------------------[snip]--------------------
I believe your example would work. However since you have a definite number
of adresses you could add the index directly, as here:
<b>Home Address:</b><br />
<input type="text" name="address[address][0]">
<input type="text" name="address[city][0]">
<b>Work Address:</b><br />
<input type="text" name="address[address][1]">
<input type="text" name="address[city][1]">
When the form is received you will have an array for adress that looks like
this:
$_REQUEST['address'] = array(
'address' => array(0 => 'home address', 1 => 'work
address'),
'city' => array(0 => 'home city', 1 => 'work city'));
To insert the home address you'd create an SQL statement like this:
for($i = 0; $i <= $number_of_addresses; ++$i) {
$sql = "insert into address(adress, city) values (" .
"{$_REQUEST['address']['address'][$i]}," .
"{$_REQUEST['address']['city'][$i]})";
// more code
}
Hope this helps,
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/