Skip to content

Instantly share code, notes, and snippets.

@slav123
Created May 9, 2014 00:46
Show Gist options
  • Save slav123/7c37b50c371cc9417c8b to your computer and use it in GitHub Desktop.
Save slav123/7c37b50c371cc9417c8b to your computer and use it in GitHub Desktop.
nice way to do rankings
<?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