seyz4all Posted July 24, 2007 Share Posted July 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/61491-how-possible-is-grading-in-mysql/ Share on other sites More sharing options...
AndyB Posted July 24, 2007 Share Posted July 24, 2007 do u think its possible and how can i achieve that.. pls help Yea. If score>74 then echo "A1" ... is enough php for that, assuming that score cannot exceed 100. Quote Link to comment https://forums.phpfreaks.com/topic/61491-how-possible-is-grading-in-mysql/#findComment-306150 Share on other sites More sharing options...
Barand Posted July 24, 2007 Share Posted July 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/61491-how-possible-is-grading-in-mysql/#findComment-306742 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.