I have a complicated array (at least it looks complicated to me). I have a form where you select a person, a start time and an end time. You can then add more people by clicking a + button. So I named the three select fields like “select_dancer[]” for an array.
When I print_r my results, it looks like this:
Array
(
[month_year] => 2011-11
[select_dancer] => Array
(
[0] => 1
[1] => 2
)
[time_from] => Array
(
[0] => 12:00pm
[1] => 1:00pm
)
[time_to] => Array
(
[0] => 12:30pm
[1] => 1:30pm
)
)
Basically, the key 0 is one person, and key 1 is another. Etc. I’m having trouble getting my head around adding this to the database. My table is basically: id, date, dancer, from, to. So I want it so I can “group” each key together and submit the values to the database.
If anyone could help me out, that would be great.
An easier approach to the field grouping would be something like this in your HTML
As each group is added, increment the number in the first square-brackets.
Your resulting
$_POSTarray would then look likeYou can then iterate the
$_POST['dancer']array for each group of values, eg (very simplified)