Created
May 9, 2014 00:46
-
-
Save slav123/7c37b50c371cc9417c8b to your computer and use it in GitHub Desktop.
nice way to do rankings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* get leaderboard data | |
* | |
* @param int $start starting position | |
* | |
* @return array | |
*/ | |
public function leaderboard($start) | |
{ | |
// set rank counting | |
$this->db->query("SELECT {$start} INTO @rank;"); | |
// get resuluts | |
$result = $this->db->select('id, @rank:=@rank+1 AS rank, name, score, city', FALSE)->limit(5, $start)->where('score', '>0')->order_by('score', 'DESC')->get('teams')->result_array(); | |
// set total ? | |
$this->total = $this->db->count_all_results('teams'); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment