Connecting Tech Pros Worldwide Forums | Help | Site Map

How to get percentage from mysql grading program

Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#1: Aug 20 '09
i want to give grade to schools according to their student pass percentage
just lile this kindly help me to find easiest way to do this

Expand|Select|Wrap|Line Numbers
  1. $sql1 = mysql_query("select count(studentid) as totstudent from result where schoolcode ='".$_GET['schoolcode']."'" );
  2.  
  3.    if(!$sql1) { echo mysql_error();}
  4.     $sql3 = mysql_query("select count(pass_fail) as totpasstudent from result where schoolcode ='".$_GET['schoolcode']."' and pass_fail='p'" );
  5.  
  6.    if(!$sql3) { echo mysql_error();}
  7.  
  8.    $paspercentage=(totpasstudent/totstudent)*100
Familiar Sight
 
Join Date: Sep 2008
Posts: 253
#2: Aug 25 '09

re: How to get percentage from mysql grading program


This is a very quick crude way to do it.
Expand|Select|Wrap|Line Numbers
  1. $sql = mysql_query("select count(studentid) as totstudent from result where schoolcode ='".$_GET['schoolcode']."'" );
  2. $row = mysql_fetch_array($sql);
  3.  
  4. $sql2 = mysql_query("select count(pass_fail) as totpasstudent from result where schoolcode ='".$_GET['schoolcode']."' and pass_fail='p'" );
  5. $row2 = mysql_fetch_array($sql2);
  6.  
  7. $paspercentag = round(($row2['totpasstudent']/$row['totstudent'])*100, 2);
Reply