I have a code that runs through database and outputs everything to a php page.
$avg = mysql_query("SELECT subject, gradeone, gradetwo, gradethree, ((gradeone + gradetwo + gradethree) / 3) as average FROM grades");
$q = mysql_query("SELECT * FROM newstudent AS n JOIN grades AS g ON n.id = g.id ORDER BY n.id") or die (mysql_error());
$last_student = null;
while ($row = mysql_fetch_assoc($q))
{
if ($row['id'] !== $last_student)
{
$last_student = $row['id'];
echo "Student ID: ".$row['id']."<br/>";
echo "First Name: ".$row['firstname']."<br/>";
echo "Last Name: ".$row['lastname']."<br/>";
echo "Email: ".$row['email']."<br/>";
echo "<br/>";
}
print "<table id=reporttable>";
print "<tr id=toprow> <td>subject</td> <td>gradeone</td> <td>gradetwo</td> <td>gradethree</td> <td>average</td></tr>";
print "<tr>";
print " <td>";
print $row["subject"];
print "</td>" ;
print " <td>";
print $row["gradeone"];
print "</td>" ;
print " <td>";
print $row["gradetwo"];
print "</td>" ;
print " <td>";
print $row["gradethree"];
print "</td>" ;
while ($r = mysql_fetch_array($avg))
{
print " <td>";
print $r['average'];
print "</td>" ;
}
print " </tr>";
print "</table>";
}?>
The desired outcome should look like this
the outcome from the following code is great, but there is only 1 minor issue.
the 2nd while loop is suppose to be calculating the average and outputting each record at a new row. instead it does this:
anyone knows a way to make it that each one of those average grades goes along with each row for students?
Try to use this query and then output the results in one single loop - remove that
with its braces.
Leave something like this: