mysql - Calculating tied ranking in php with pagination -
this first question here, please tell if unclear or need know more. i've provided information need.
i got page calculating cycling rankings in norway. riders gets point in each race, , calculate overall ranking. until have calculated ranking after each race , saved overall points , rank in database. have been frustrating, since had run calculation after every small change or update.
in updated page calculate overall points , ranking using php-code inside loop when displaying table (all 3 rank variables set 0 before loop):
$rank_tmp++; if ($rankpoints!=$row["points"]) { $rank=$rank_tmp; } echo $rank
this simple code works well, , give me ranks ties.
the challenge when use pagination split results on each page.
in query , code i've added:
limit $starting_position, $records_per_page"; $starting_position=($_get["page_no"]-1)*$records_per_page;
to ranking continue on page 2 expanded loop with:
$rank_tmp++; if ($rankpoints!=$row["points"]) { $rank=$rank_tmp; } echo $rank + $starting_position;
this works intended, if set ´$records_per_page=50´ first rider on page 2 gets rank 51 , on.
the problem is: if rider 50 , 51 both have same number of points, rider 51 still rank 51 , not 50 should.
so how calculate ranking, ties, when using pagination?
Comments
Post a Comment