ricky_vancouver Posted December 11, 2010 Share Posted December 11, 2010 Hey long time no post So my problem, i am developing a grading system for my college and a function i wrote to work out the grade for the course is based on there current system but modified to be more flexible. The problem is is that i don't know if my maths is correct in it, and have no way to reliably test it. So, the function function WorkOutYearGrade($ProgID){ $ProgID = SecureVar($ProgID); $sql_check = mysql_query("SELECT * FROM student_grade WHERE program_id = '".$ProgID."' AND PSN = '".$_SESSION['PSN']."'"); if(mysql_num_rows($sql_check) != 0) { $sql = mysql_query("SELECT id FROM units WHERE program_id = '".$ProgID."'"); $distinction = 0; $merit = 0; $pass = 0; while($rows = mysql_fetch_assoc($sql)) { $grade = work_out_grade_average("program",$ProgID,$rows['id']); if($grade == "Pass") { $pass += (6 * mysql_num_rows($sql)); } elseif($grade == "Merit") { $merit += (12 * mysql_num_rows($sql)); } elseif($grade == "Distinction") { $distinction += (18 * mysql_num_rows($sql)); } } $points = round(($distinction) + ($merit) + ($pass)); $ExpPoints_d = 18 * mysql_num_rows($sql); $ExpPoints_m = 12 * mysql_num_rows($sql); $ExpPoints_p = 6 * mysql_num_rows($sql); $dist = $ExpPoints_d + $ExpPoints_m + $ExpPoints_p; $merit = $ExpPoints_m + $ExpPoints_p; $pass = $ExpPoints_p; if($points == 0) { return "<span style=\"color:red;\">R</span>"; } else { switch($points) { case $points >= $dist; return "DDD"; break; case $points >= $merit + (48 * mysql_num_rows($sql)); return "DDM"; break; case $points >= $merit + (24 * mysql_num_rows($sql)); return "DMM"; break; case $points >= $merit; return "MMM"; break; case $points >= $pass + (48 * mysql_num_rows($sql)); return "MMP"; break; case $points >= $pass + (24 * mysql_num_rows($sql)); return "MPP"; break; case $points >= $pass; return "PPP"; break; default; return "<span style=\"color:red;\">R</span>"; break; } } }} It is based on their point system which is: a pass = 6 a merit = 12 a distinction = 18 The point system the college was using is based on having 18 units where as mine is dynamic and based on how many units there are. Direct from their spreadsheet system: Quote Link to comment https://forums.phpfreaks.com/topic/221296-complicatedmaths-issue/ Share on other sites More sharing options...
trq Posted December 11, 2010 Share Posted December 11, 2010 Can you format your code so it is readable? Quote Link to comment https://forums.phpfreaks.com/topic/221296-complicatedmaths-issue/#findComment-1145692 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.