Benjamin Asamoah
Benjamin Asamoah

Reputation: 1

How to Rank Student Marks in Codeigniter Function

Can someone please help me to get the student rank function in codeigniter. How can I rank their subject mark of each subject of each student on their report. this is an example below. I want to get something like this;

Name: Ben Wade
|Subject  |Test Score| Rank | Grade |  Remarks |
| English |    87    |  2   |   A+  | Excellent|
| Maths   |    76    |  3   |   B+  | V. Good|

Name: John Doe
|Subject  |Test Score| Rank | Grade |  Remarks |
| English |    97    |  1   |   A+  | Excellent|
| Maths   |    81    |  1   |   A+  | Excellent|

Upvotes: 0

Views: 1514

Answers (1)

Eisa Adil
Eisa Adil

Reputation: 1733

$highest_marks = $this->db->get('mark')->result_array();
rsort($highest_marks);
foreach($highest_marks as $row) {
        echo $row['mark_obtained'];
}

Retrive the resut_array() and then rsort() which would sort it in descending order. Hope it helps. :)

Upvotes: 1

Related Questions