I have code that ranks students and it works, but not as I intended -- if two or more students score the same score
it doesn't rank
them both in the same rank
. I want the final ranking to be like this - if two or more students score
the same result, I want them to rank
in the same place like this:
1. miki ==> 97.8
2. lisa ==> 96.1
2. jack ==> 96.1
4. john ==> 90.7
Note that lisa and jack score
the same (96.1
), and it gives them the same rank
(2nd), and therefore, 3rd is skipped. John is 4th.
Current code
$student = '10_E';
$first = mysql_query("SELECT * FROM rej_students where student_selected = '$student'");
$teacher = mysql_query("SELECT * FROM teachers WHERE tech_id = '1002'");
$teachers = mysql_fetch_array($teacher);
$avg = mysql_query("SELECT * FROM avgfct_10 order by AVGFCT_10 desc");
$ra = 0; //rank
while ($go = mysql_fetch_array($avg))
{
if ($go['AVGFCT_10'] != $go['AVGFCT_10'])
{
$micky = $ra ++;
}
if ($go['AVGFCT_10'] == $go['AVGFCT_10'])
{
$micky = 'same';
}
echo "id = " . $go['STUDENT_ID'] . "<br> AVARANGE = " . $go['AVGFCT_10'] . "<br>RANK = " . $micky . "<br> Class = " . $teachers['tech_hclass'] . "<br><br>";
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…