verdrm Posted September 1, 2007 Share Posted September 1, 2007 Does anyone know how to calculate GPA using PHP? Quote Link to comment Share on other sites More sharing options...
php_tom Posted September 1, 2007 Share Posted September 1, 2007 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? Quote Link to comment Share on other sites More sharing options...
corbin Posted September 3, 2007 Share Posted September 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 3, 2007 Share Posted September 3, 2007 I don't remember how to calculate a GPA, so that could be entirely wrong, but.... lol http://www.cas.unt.edu/advising/gpacalc.htm Quote Link to comment Share on other sites More sharing options...
corbin Posted September 3, 2007 Share Posted September 3, 2007 Ahhh.... It's all coming back now (which is odd considering I'm in highschool haha)... Anyway, if you wanted to do the loop inside of mysql instead of PHP, you could do a query like: SELECT SUM(grade*credits)/SUM(credits) AS gpa FROM Grades WHERE student_id = 1 Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 3, 2007 Share Posted September 3, 2007 Does anyone know how to calculate GPA using PHP? To get back to the question, the answer is that php has nothing to do with it. GPA is calculated using standard math (see Barand's link) regardless of the scripting/programming language that's used. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 3, 2007 Share Posted September 3, 2007 When Andy and I were in school, scratching with chalk on slate tablets, GPAs hadn't been invented. So this is all new to me Quote Link to comment Share on other sites More sharing options...
d22552000 Posted September 4, 2007 Share Posted September 4, 2007 lolololol we had paper. and some pencils.. and a good fountain pen per person. thats just about all, although textbooks were pretty new. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.