Jump to content

Calculating GPA


verdrm

Recommended Posts

If you have a table for classes with these fields:

 

Class                  NumCredits            Grade

---------------------------------------------------

Biology 532          6                          3.5        (AB)

Basket-Weaving    3                          2.0        ©

Philosophy 773      4                          4.0        (A)

 

You can get the GPA like so:

 

<?php
$link = mysql_connect(...);
mysql_select_db(...);
$tot_credits = 0;
$tmp_gpa = 0;
$res = mysql_query("SELECT * FROM classes");
while($row = mysql_fetch_assoc($res)) {
   $tmp_gpa += $row['Grade']*$row['NumCredits'];
   $tot_credits += $row['NumCredits'];
}
$gpa_final = round(($tmp_gpa/$tot_credits),3);
?>

 

Is this sort of what you wanted?

Link to comment
https://forums.phpfreaks.com/topic/67534-calculating-gpa/#findComment-339151
Share on other sites

If you had something like this:

 

student_id     class     credits      grade
------------------------------------------
1                Biology        1             4
2                Algrebra      1             3

 

You could do something like:

 

<?php
//connect
$q = mysql_query('SELECT AVG(credits*grade) FROM grades WHERE student_id = 1');
?>

 

I don't remember how to calculate a GPA, so that could be entirely wrong, but.... lol

Link to comment
https://forums.phpfreaks.com/topic/67534-calculating-gpa/#findComment-340813
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.