[eluser]chrislorenz[/eluser]
Hi all!
First off I just want to say what a great framework and what an amazing community. This is the first time I have had to ask a question since my start with codeigniter due to the wealth of info on these forums and the userguide.
My question may be noob in nature so bare with me.
I currently am created a voting system where users can vote on individual submissions that people create.
I have created a function in my model that joins various tables and can give me how many votes an individual submission has, which works great. Now my issue is that I want to be able to reference that query but give me a "rank" of the submission by finding what row id is returned.
Below is the function in my model:
Code:
function get_submissions_rank($subid)
{
$this->db->select('*');
$this->db->select('COUNT(vote.vote_id) AS VoteCount');
$this->db->from('submission');
$this->db->join('vote','vote.submission_id = submission.submission_id', 'inner');
$this->db->group_by('vote.submission_id');
$this->db->order_by('VoteCount', 'DESC');
$this->db->where('submission.submission_id', $subid);
$query = $this->db->get();
return $query->result_array();
}
Now I know that I can do a foreach loop and reiterate i++ to find the rank but it seems like it would be an inefficient way to do it. (especially since this query would be running a lot and the amount of records has the potential to be pretty large).
Does anyone know the best way to handle something like this? Let me know if I need to explain further.
Thanks in advance!
Chris
@chrislorenz