I am running the following code, which runs a query, gets all the student_id's in a class, then for each student id it gets all their grades. My problem is though that the data put into the array doesnt stay in it when it goes back and runs the for loop for the second, third, etc student. Is there a way to keep the data in the array and keep adding to it? I have included some code below to help paint the picture. Thanks All
$sql = "SELECT student_id FROM users_table WHERE class_id ='5'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$row_cnt = mysqli_num_rows($result);
$students = array();
for($y=0; $y<$row_cnt; $y++)
{
array_push($students, $row['student_id']);
$sql2 = "SELECT student_grade FROM grades_table WHERE student_id ='".$students[$y]."'";
$result2 = $db->sql_query($sql2);
$row2 = $db->sql_fetchrow($result2);
$row_cnt2 = mysqli_num_rows($result2);
for($z=0; $z<$row_cnt2; $z++)
{
array_push($students, array($row['student_grade']));
}
}