General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 9th, 2003, 05:48 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Question Multiple Record Inserting??/

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

Reply With Quote
  #2  
Old February 9th, 2003, 10:42 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
on your form,...

Code:
<input type="text" name="array1[]" />


your php part...

PHP Code:
for($i=1; $<=sizeof($array1[]); $i++)
{
   
mysql_query("insert into.....");



that may help a bit
__________________
-- Jason

Last edited by Taelo : February 10th, 2003 at 10:12 AM.

Reply With Quote
  #3  
Old February 9th, 2003, 06:38 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
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:
<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

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:
for ($i=0;$i<=12;$i++) {
    for (
$ii=0;$ii<=40;$ii++) {
       
//insert into table code
    
}


im just not sure home to put the whole thing together

Reply With Quote
  #4  
Old February 9th, 2003, 11:11 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
yeah something like that would work

Reply With Quote
  #5  
Old February 9th, 2003, 11:25 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Question

How do i get the form variables into the 2 arrays ?

Reply With Quote
  #6  
Old February 10th, 2003, 11:11 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
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

Reply With Quote
  #7  
Old February 10th, 2003, 07:15 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
hi, im really stupid, could you post the actual code for doing this, please.

Reply With Quote
  #8  
Old February 10th, 2003, 10:18 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Once you submit the page you need something like this

PHP Code:
foreach($item as $id=>$value)
{

$vItem $value;
$vPrice $price[$id];
$vCategory $category[$id];





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>

Reply With Quote
  #9  
Old February 10th, 2003, 10:19 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Once you submit the page you need something like this

PHP Code:
foreach($item as $id=>$value)
{

$vItem $value;
$vPrice $price[$id];
$vCategory $category[$id];





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)");

Reply With Quote
  #10  
Old February 10th, 2003, 11:25 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
Ben is da man

Reply With Quote
  #11  
Old February 11th, 2003, 02:07 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Thanks Ben,
as Black Adder said, "I love you and want to have your baby!"

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Multiple Record Inserting??/


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT