Jump to content

How possible is grading in mysql


seyz4all

Recommended Posts

i wanna ask, if i am to create a column that would read data from the other column

 

in the case of grade column for school.

 

where A1 represents score from 75-100 i.e it should read the total score column to display A1.

 

do u think its possible and how can i achieve that.. pls help

Link to comment
https://forums.phpfreaks.com/topic/61491-how-possible-is-grading-in-mysql/
Share on other sites

You could do something like this, changing values to suit your situation

 

<?php

$sql = "SELECT  score,
    (CASE 
        WHEN score BETWEEN 75 AND 100 THEN 'A1'
        WHEN score BETWEEN 70 AND 74  THEN 'A2'
        WHEN score BETWEEN 65 AND 69  THEN 'B'
        WHEN score BETWEEN 60 AND 64 THEN 'C'
        WHEN score BETWEEN 50 AND 59  THEN 'D'
        ELSE 'Fail' END) as grade
    FROM ratings";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
while (list($scr, $grd) = mysql_fetch_row($res))
{
    echo "$scr : $grd<br>";
}
?>

With my data gives

 

75 : A1

74 : A2

63 : C

59 : D

54 : D

49 : Fail

70 : A2

66 : B

 

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.