Rasiel
Rasiel

Reputation: 2913

In PHP/CodeIgniter how do you calculate Class & Form Rank based on grades for a student?

I have a database table that holds the following grade information for a student:

student_id
subject_id
gpa
letter_grade (which is calculated based on gpa, & inserted when record is saved)
semester

6   518 95  A+  1

6   534 100 A+  1

I then calculate an end-of-semester report based on the grades. I use the gpa to calculate the credits applied and the overall GPA. Based on this overall GPA, I want to calculate rank for the student for his class and his form (grade level) overall. How do I do this without saving into the database this rank prior? Also, can this be done from a view in CodeIgniter? If so, what;s the best way to do it?

Upvotes: 0

Views: 1860

Answers (4)

Chris
Chris

Reputation: 6325

  1. Can this be done in Code Igniter? Yes you should be able to.

  2. Should this be done in the view? No you should not be doing your calculations in a view. Make a class and bring that in when you're creating a model to handle the grades. Your view should only be used to render your user interface.

Upvotes: 1

Shane
Shane

Reputation: 697

I wouldn't recommend calculating anything in the view.

I would suggest if your using codeigniter to go with an MVC framework, then possibly have a model representing the functionality you're describing and a controller to pull this model and your view together.

I would also suggest this video tutorial on codeigniter for a very good overview of the framework and on coding MVC applications.

Upvotes: 0

bradym
bradym

Reputation: 4961

I'd suggest doing this in the Model when you are getting your data from MySQL. That way your data is all sorted and ready to use when you get it back.

Take a look at http://rpbouman.blogspot.com/2009/09/mysql-another-ranking-trick.html for a way to rank data in a SQL query.

Upvotes: 1

Related Questions