$q = mysql_query("
SELECT
n.id,
n.firstname,
n.lastname,
n.email,
g.gradeone,
g.gradetwo,
g.gradethree,
((g.gradeone + g.gradetwo + g.gradethree) / 3) AS average
FROM
newstudent n JOIN grades g USING (id)
ORDER BY
n.id
") or die (mysql_error());
Coba gunakan kueri ini, lalu keluarkan hasilnya dalam satu putaran - hapus
while ($r = mysql_fetch_array($avg))
dengan kawat giginya.
Tinggalkan sesuatu seperti ini:
....
print "<td>$row['gradetwo']</td>";
print "<td>$row['gradethree']</td>";
print "<td>$row['average']</td>";
....