|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, I have a form where i want to be able to add five items to a database at the same time, i know i have to create an array somehow to be able to insert all 5 records in one go.
How do i create the array?
__________________
regards, Fulton |
|
#2
|
|||
|
|||
|
on your form,...
Code:
<input type="text" name="array1[]" /> your php part... PHP Code:
that may help a bit
__________________
-- Jason Last edited by Taelo : February 10th, 2003 at 10:12 AM. |
|
#3
|
|||
|
|||
|
maybe i should explain it better:
I have a form, in that form i have 5 seperate items and in each item are 3 text fields, i have to create 2 arrays. My Form: PHP Code:
WHAT I NEED. 1 array should be for the 5 items and 1 array should be for the 3 text fields in each item. so its going to be a nested for loop i think, something maybe like PHP Code:
im just not sure home to put the whole thing together |
|
#4
|
|||
|
|||
|
yeah something like that would work
![]() |
|
#5
|
|||
|
|||
|
How do i get the form variables into the 2 arrays ?
|
|
#6
|
|||
|
|||
|
by using "item1[]" in your form,...you are initializing the array,..such that when the form is processed,..item1[] looks like
item1[] 1 => this item 2 => second item etc,..etc..... then just use a nested for loop to parse through each set of arrays |
|
#7
|
|||
|
|||
|
hi, im really stupid, could you post the actual code for doing this, please.
|
|
#8
|
|||
|
|||
|
Once you submit the page you need something like this
PHP Code:
Then each of those variables will be what ever you entered in the pevious page, They will loop though it untill the array as finished Then if you want to insert that data into a database add the following code into the loop, after <form> ITEM 1 <input name="item[]" type="text"> <input name="price[]" type="text"> <input name="category[]" type="text"> ITEM 2 <input name="item[]" type="text"> <input name="price[]" type="text"> <input name="category[]" type="text"> ITEM 3 <input name="item[]" type="text"> <input name="price[]" type="text"> <input name="category[]" type="text"> ITEM 4 <input name="item[]" type="text"> <input name="price[]" type="text"> <input name="category[]" type="text"> ITEM 5 <input name="item[]" type="text"> <input name="price[]" type="text"> <input name="category[]" type="text"> <input type="submit" name="Submit" value="Insert"> </form> |
|
#9
|
|||
|
|||
|
Once you submit the page you need something like this
PHP Code:
Then each of those variables will be what ever you entered in the pevious page, They will loop though it untill the array as finished Then if you want to insert that data into a database add the following code into the loop, after the variables have been set mysql_query("insert into table values (0, $vItem, $vPrice, $vCategory)"); |
|
#10
|
|||
|
|||
|
Ben is da man
|
|
#11
|
|||
|
|||
|
Thanks Ben,
as Black Adder said, "I love you and want to have your baby!" |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Multiple Record Inserting??/ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|