Hi PHP people, i've stumbled into something that my current level of MySQL knowledge doesnt allow me to resolve. Perhaps someone can throw in an idea or two. I'll start from afar...
Project involves developing electronic journal for school.
For this question one table from the database is used:
'marks' table with these fields:
id, date, studentid, subjectNo, mark
You select date range and subject No from a form before displaying this one.
Outputting it is pretty easy,
but when you try filling it with values using a reallife school journal like form is where it gets tricky.
So this input form after generation looks roughly like this:
a table with alot of small input fields containing marks and a submit button.
--------------------Subject No.1(Mathematics)------------
------------15.05 16.05 17.05 18.05 19.05 20.50----
student1 |[-] [-] [5] [-] [-] [5]
student2 |[-] [4] [-] [-] [-] [3]
student3 |[1] [5] [3] [-] [-] [3]
.........etc
['Save to database' button]
Marks displayed in [] brackets have the following code:
echo "<td align=\"center\"><input name=\"". $i . ":" . $j . "\" type=\"text\" value=\"". $curMark ."\" size=\"1\" maxlength=\"1\" onFocus=\"select();\"></input></td>";
so basically after gathering data from form on output i have a
3d array with students and their marks.
student1[date][mark]
[date][mark]
[date][mark]
..............etc
student2[date][mark]
[date][mark]
[date][mark]
..............etc
student3[date][mark]
[date][mark]
[date][mark]
..............etc
And now, to my question:
To put all these values back into database, i will need do an iteraction cycle through all that array and do a
if($array[value] != "-") // not empty
mysql_query("REPLACE INTO 'marks' VALUES etc, etc ");
for each existing mark input field.
As i understand MySQL databases, it usually operates row by row, but seeing as each mark is stored on its separate row, my code produces a wild amount of queries.
Is there a way to put the whole array into database, or at least decrease the amount of SQL queries?