Hi...I'm new here and new to PHP, so play nice!
I have a simple form that sends up to 30 sets of 4 inputs. I.E. these inputs can be set up to 30 times:
<form action="insert_gig.php" method="post" target="_blank">
<select name="setnum[]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<select name="song[]">
<option value="1" size="10">100 Rockets</option>
<option value="2" size="10">101st Lament</option>
<option value="3" size="10">1776</option>
<option value="4" size="10">66 Sleepers To Summer</option>
</select>
<select name="style[]">
<option value="1">Album/Studio</option>
<option value="2">Single</option>
<option value="3">Demo</option>
<option value="4">Acoustic</option>
<option value="5">Extended Intro</option>
<option value="6">Extended Outro</option>
</select>
<p>Encore:</p>
<select name="encore[]">
<option value="N">No</option>
<option value="Y">Yes</option>
</select><br/><br/>
<select name="setnum[]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
As you can see I'm puling each in as an array. I can get each array to print out in its own as such:
foreach($_POST['song'] as $value1){
echo "<p>Song: $value1</p><br/>\n";
}
foreach($_POST['setnum'] as $value2){
echo "<p>Song Number: $value2</p><br/>\n";
}
foreach($_POST['style'] as $value3){
echo "<p>Song Style: $value3</p><br/>\n";
}
foreach($_POST['encore'] as $value4){
echo "<p>Encore: $value4</p><br/>\n";
}
However, I am attemping to access each array with one loop so I can insert the values in an SQL statement that will run up to 30 times.
I would like to insert it into the following:
$query = "INSERT INTO `setlist` ( `setlist_id` , `gig_id` , `venue_id` , `setlist_number` , `track_id` , `song_style_id` , `encore` )
VALUES ('', '$gig', '$venue', '$val2', '$val1.', '$val3', '$val4')";
So how can I get it so I can loop through all of the arrays simultaneously so that the first loop through of the query pulls in the first values of each array, the second loop through the query pulls in the second values of the arrays, etc.
Thank you so much for the help!