I am working on a Database that manipulates college students exam results. Basically, I am pulling the records from a MySql Database, puling one class at any given time. I want to rank the students, with the highest performer at number 1.
I have try to read this article but it show me only single array :
http://stackoverflow.com/questions/6163225/how-do-i-rank-array-values-with-duplicate-values-and-skipping-some-positions-if
Here is an illustration;
get result and make and array
$grades = array();
foreach($results->result() as $row){
$grades[] = array('rank'=>$row->total,'name'=>$student_name);
}
array result :
$grades[] = array(
array('rank'=>"123","name"=>"samphors"),
array('rank'=>"123","name"=>"sovann"),
array('rank'=>"102","name"=>"dy vann"),
array('rank'=>"113","name"=>"koro vann")
);
So I want to capture Mysql data as a multiple array. Once I have the data in an array, I should then assign each student a position in the class such as 1/10 (number 1, the 123 score), 4/10 etc. Now the problem is that if there is a tie, then the next score skips a position and if there are 3 scores at one position then the next score skips 2 positions. So the scores above would be ranked as follows;
----------------------------------
| no | name | score | rank |
| 1 |samphors | 123 | 1 |
| 2 |sovann | 123 | 1 |
| 3 |koro vann | 113 | 2 |
| 4 |dy vann | 102 | 3 |
----------------------------------
Is it possible (humanly possible /php possible) to use PHP to rank the scores and name of student above in such a way that it can handle possible ties such as 4 scores at one position? SADLY, I could not come up with a function to do this. I need a PHP function (or something ... PHP) that will take an array and produce a ranking as above.
Any help will be deeply appreciated, though I think I may be asking for too much. If it's possible to do this with MySQL query data without having it in an array, then that will also be helpful!