Somebody said I could not combine the two query's together. The SELECT and INSERT INTO.
So..
I hardcoded it and I get back 104.
This:
$getgrades = $db->sql_query("SELECT Course_ID, SOMS_KEY, UID, Academic_Year, AVG(TL_Avg) AS FinalGrade
FROM ".$prefix."_tl_session_grades sg
JOIN ".$prefix."_tl_session s ON (s.Session_ID = sg.Session_ID)
WHERE s.Course_ID = '$Course_ID'
GROUP BY sg.SOMS_KEY");
if (!$getgrades) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
$total = $db->sql_numrows($getgrades);
OpenTable();
echo"<tr><td>$total</td></tr>";
CloseTable();
die();
Displays 104
While the rest of the code will insert 312 records:
while($row = $db->sql_fetchrow($getgrades)) {
$Course_ID = $row[Course_ID];
$SOMS_KEY = $row[SOMS_KEY];
$UID = $row[UID];
$Academic_Year = $row[Academic_Year];
$FinalGrade = $row[FinalGrade];
$insertgrades = $db->sql_query("INSERT INTO ".$prefix."_tl_course_grades (Course_ID, SOMS_KEY, UID, Academic_Year, Final_Grade)". "VALUES ('$Course_ID', '$SOMS_KEY', '$UID', '$Academic_Year', '$FinalGrade')");
if (!$insertgrades) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
}
What the....?