Hi I am very new at this but am stuck with what may be a fairly simple problem and I really need a clue.
I have constructed an html form that has multiple rows: one row for each student. Each row starts with the values of the student name and ID number the user is to enter a test date and the scores on several tests. Let's say the data fields for each record are Name, ID, Testdate, Score1, Score2, Score3, Score4. The Name and ID fields get filled in by a query run from a previous page, so the user only has to give the test date and the test score data.
The form is constructed such that it contains all the rows and therefore has only a single "submit" button at the end so that the teacher can submit the whole class to the database all at once.
I have figured out how to pass the form data to a subsequent php script using a multidimensional array:
$datarecords = array ($HTTP_POST_VARS['Name'], $HTTP_POST_VARS['ID'], $HTTP_POST_VARS['TESTDATE'], $HTTP_POST_VARS['Score1'], $HTTP_POST_VARS['Score2'], $HTTP_POST_VARS['Score3'], $HTTP_POST_VARS['Score4']);
Here is where I get stuck:
I want to pass each row of this form as separate records to a mysql database. I understand how to do this with single-record forms, but I am stumped about how to go about parsing this multidimensional array described above and formatting the output for mysql INSERT. I suppose it has something to do with nested "for" or "foreach" looping or something like that but I am really having trouble.
The closest I have gotten is the line:
{for ($n = 0; $n < 4; $n++) {for ($m = 0; $m < count($datarecords); $m++) echo ($datarecords[$m][$n]);}echo "<br>\n";}
...this at least sets the values in the proper order, but I don't understand how to fit in the quotes and commas and parentheses and stuff that will be needed to send the data on to my mysql table.
Anybody? (Thanks in advance!)
(note: the "$n<4;" value in the previous statement is temporary....that value needs to be dynamic because the number of rows/records from the original form is going to vary depending on the classroom size).😕