Jump to content

Writing calculations back to table


Donovan

Recommended Posts

I am working on a grading app for the university I work for.  So far this is what I have:

 

After gathering the grade info I insert to a table

 

$insertgrades = $db->sql_query("INSERT INTO ".$prefix."_tl_course_grades (Course_ID, SOMS_KEY, UID, Academic_Year, Irat_Avg, Grat_Avg, Appex_Avg) SELECT s.Course_ID, g.SOMS_KEY, g.UID, g.Academic_Year, AVG(IRAT_Grade) AS Irat_Avg, AVG(GRAT_Grade) AS Grat_Avg, AVG(Appex_Grade) AS Appex_Avg
FROM ".$prefix."_tl_session_grades g
JOIN ".$prefix."_tl_session s ON (g.Session_ID = s.Session_ID)
JOIN ".$prefix."_tl_courses c ON (s.Course_ID = c.Course_ID)
WHERE c.Course_ID = '$Course_ID'
GROUP BY g.SOMS_KEY");
if (!$insertgrades) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}

 

I then compute another average of Appex and Grat and write that to GRAT_AppEx_Avg.  I don't know if this is correct but it appears to be working.

 

$updategroupavg = $db->sql_query("UPDATE ".$prefix."_tl_course_grades SET GRAT_AppEx_Avg = (SELECT AVG(Grat_Avg + Appex_Avg)/2 AS GRAT_AppEx_Avg)");
if (!$updategroupavg) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}

 

I then select the "weights" to assign for each part of the grade.  Some parts are weighted more than others. 20%, 40% etc.

 

$getweightinfo = $db->sql_query("SELECT * FROM ".$prefix."_tl_class_weights cw JOIN ".$prefix."_tl_weights w ON cw.weight_id = w.weight_id WHERE Class_Year = '$Course_Year'");
if (!$getweightinfo) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}
while($info = $db->sql_fetchrow($getweightinfo)) {
$irat_wt = $info[irat_wt];
$grat_wt = $info[grat_wt];
$appex_wt = $info[appex_wt];
}

 

Then I am trying to compute the Final grade and here is where I need some help.

 

$processfinalgrade = $db->sql_query("SELECT * FROM ".$prefix."_tl_course_grades WHERE Course_ID = '$Course_ID'");
if (!$processfinalgrade) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}
while($row = $db->sql_fetchrow($processfinalgrade)) {
$IRAT_Avg = $row[iRAT_Avg];
$GRAT_Avg = $row[GRAT_Avg];
$Appex_Avg = $row[Appex_Avg];
$Grade = (($IRAT_Avg * $irat_wt) + ($GRAT_Avg * $grat_wt) + ($Appex_Avg * $appex_wt));
}

 

Update the table

 

$updatefinalgrade = $db->sql_query("UPDATE ".$prefix."_tl_course_grades SET Final_Grade = '$Grade' WHERE Course_ID ='$Course_ID'");

 

which is not writing the correct Final grade.  I get a repeating 67%.

 

Any help is appreciated.

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.