Hi all,
I am developing a mini-game, in which the results will be stored in a database. I need to display the player's score, showing him where he ranks. For instance, if the player is ranked as the 10th position, then I will need to show the score for the 5th position to 15th position.
I could simply use ORDER BY and LIMIT to get the results I need, maybe something like this:
SELECT player_name, score FROM highscore WHERE score < $player_score ORDER BY score DESC LIMIT 0, 5;
and
SELECT player_name, score FROM highscore WHERE score > $player_score ORDER BY score DESC LIMIT 0, 4;
The problem is I have no idea what will be the position of the player. I could get the entire result-sets and do a sort, thus knowing which position of the player, but it strikes me as ineffective. Is there a better way?
Thanks in advance!
Sorting problem. Need to know sorting order of a record
Moderator: General Moderators
-
LonelyProgrammer
- Forum Contributor
- Posts: 108
- Joined: Sun Oct 12, 2003 7:10 am
-
LonelyProgrammer
- Forum Contributor
- Posts: 108
- Joined: Sun Oct 12, 2003 7:10 am