Originally posted by sandgnat
I have never constructed anything like
$_POST['name'][$loop]
and didn't know it could be done. Not still sure how it works but at least it's in my code toolbox so to speak.[/B]
Well, it's simply a multidimensional array --- in PERL, they call it a "hash" ... I'm not mathematician nor physicist enough to give a scientific explanation, but basically $_POST is an array (of everything that was submitted in the form), ['name'] is also an array (it could just as easily be a single variable, but it's not ...) of all the "names" that were input into the form. "score" is a similar array. These two "sub-arrays", if you will, are indexed numerically by PHP, starting at zero.
We could just as easily have done:
$namearray=$_POST['name'];
$scorearray=$_POST['score'];
foreach ($namearray as $n, $scorearray as $s) {
echo "<br>$n --- $s";
}
Didn't test it, but it should work. It's what [man]foreach/man was created for.
There is one critical point here. If, by some chance, a particular field is NULL, then from that point on you could accidentally be inserting Ms. Norris' grade for Mr. Miles, and Mr. Osborne's for Ms. Norris, and etc., etc. ...
So, a sanity check might be a good thing. Perhaps compare the [man]count/man of the two arrays and halt processing if they are not the same size ...
Have a good week at school 🙂