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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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