Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
foreach or loop
jamesd116



Joined: 05 Jun 2006
Posts: 1559
Location: Rochester Pa

Posted: 09/04/11 07:31 
I have a module with 4 fields including the id I want to be able toxcreate multiple entries into the db at one time

the form is set up as follows
Field 2
field 3

What I want is the below to be submitted multiple times with one submission field one obviously is the id so it would do what it does automatically
fields 2 and 3 will have the same info in it when submistted
field 4 which is the one that is being submitted with a different entry into it for each one how do i click submit have the form submitted once using the first field 4 then loop back around and do field 1 2 3 and the next field 4 entry again so for the example below it would give me 6 entries at once saving me time by not doing so much repetition. I believe this may be donw in the save.php but not sure if it should be done in the create.php
I have been googling an answer to this for months now.

field 4
field 4
filed 4
field 4
field 4
field 4


_________________
One day the court system will learn that a childs mother is not the only option...... Question is will it be too late by that time...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/04/11 20:42 
I dont really understand a lot of the stuff in your question above, but if you want to INSERT multiple rows into a database in a single go then the foreach loop is what you want.

foreach($array_of_stuff as $single_item){

$sql = "INSERT INTO jamroom_YourTableName (col1, col2, col3) VALUES ({$single_item['first_thing']}, {$single_item['second_thing']}, {$single_item['third_thing']}) ";
$_ct = dbQuery($sql, 'COUNT');
if($_ct > 0){
//success
}else{
//failed
}

}


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
jamesd116



Joined: 05 Jun 2006
Posts: 1559
Location: Rochester Pa

Posted: 09/04/11 21:01 
Thanks ussher a few questions real quick

1) does this go intot he create or the save file probablyu the save.php right?
2) on the for each statement $array of stuff (what is this going to be)
3) $single item is this the fiield that will be entered multiple times with the different data
4) dirst, second and thrid thing im thinking is matching up with the cols 1,2,3


_________________
One day the court system will learn that a childs mother is not the only option...... Question is will it be too late by that time...
Back to top
jamesd116



Joined: 05 Jun 2006
Posts: 1559
Location: Rochester Pa

Posted: 09/04/11 21:03 
actually after thinking about it I am thinking it goes in the create file


_________________
One day the court system will learn that a childs mother is not the only option...... Question is will it be too late by that time...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/04/11 21:07 

jamesd116:
1) does this go intot he create or the save file probablyu the save.php right?

I cant answer that. It goes into wherever your module is doing the insert. (I hope your not changing any core jamroom files. real bad idea.)


jamesd116:
2) on the for each statement $array of stuff (what is this going to be)

its going to be the info that you want to go into the database.


jamesd116:
3) $single item is this the fiield that will be entered multiple times with the different data

That is the single item data. Like if you get all the songs from the database, then single_item would be one song. each song has a name and an id and length etc, etc.....


jamesd116:
4) dirst, second and thrid thing im thinking is matching up with the cols 1,2,3

then yes, these would be the items in single_item.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.