I'm trying to populate a group of textboxes with data queried from a database.
The php for loop runs 4 times, evidenced by 4 names in the pulldown. However, only the first two pulldown options work (populating the text boxes, not shown here)
echo "<script> var students = [[],[]];";
$students = "";
for($i=0; $i<$query->rowCount(); $i++) {
echo "students[$i][0] = " . $result[$i]['studentID'] . ";";
echo "students[$i][1] = " . $result[$i]['coachID'] . ";";
echo "students[$i][2] = " . $result[$i]['schoolID'] . ";";
echo "students[$i][3] = '" . $result[$i]['firstName'] . "';";
echo "students[$i][4] = '" . $result[$i]['lastName'] . "';";
echo "students[$i][5] = " . $result[$i]['grade'] . ";";
$students .= "<option value='$i'>" . $result[$i]['firstName'] ."</option>";
}
echo "</script>";
Chrome's debugger throws an error on page load, "Uncaught TypeError: Cannot set property '0' of undefined" referencing the line of php-generated code, "students[2][0] = 56784"
I put the message in Google, and found this page which confirms (I think?) that the for loop is only filling students[][] with 2 of the 4 records.
I can't figure out why it works just fine for the first two and not for the other two. Please tell me this isn't a simple syntax error.