Welcome Guest, Not a member yet? Register   Sign In
Student Ranking
#1

Hello guys I need help....i need to rank students position using their marks which i have in my database table, i e with the highest marks is no 1 and so on and if they have same marks to have same no.I have searched the net but am not getting the answer to my problem..or Any advice will be appreciated...Thanks in advance.
Reply
#2

(This post was last modified: 12-30-2015, 09:51 AM by mwhitney.)

Normally, this would be a simple order by statement in your SQL (or using $this->db->order_by() if you're using Query Builder). However, I'm guessing that you need to actually compute their marks based on the data in the table, rather than having the computed value stored in the table. The problem can be complicated further by some database structures. The basic idea and some of the complications caused by some structural issues are discussed in this stack overflow question. For instance, it's relatively simple to do:

Code:
select
    student,
    sum(mark1+mark2+mark3) as total_marks
from marks
group by student


but you would have to know the column names in advance (and update the query every time more columns are added), and may have to add some handling for null values, etc.

As the last answer on that page demonstrates, it becomes simpler if the schema is normalized, though other operations may be slightly more complicated with normalized data.

Once you have the SQL figured out, it's fairly easy to translate that into a method/function in your model to run the query and return the data to your controller.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB