Creating a ranking
| From: | EDB) | Date: | Tue, 16 Jan 2001 12:51:08 +0000 |
| Subject: | Creating a ranking | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-5898@lists.php.net to get a copy of this message | ||
Hej alla,
First of all, a Happy New Year for all of you! My vacations are gone and I now have to come back to
my true reality... Databases and PHP. :)
A very interesting question for you experts. Let's see if you can help me.
I am developing a game with a team and I have to store the scores of users on a MySQL database to
create a ranking. I have a MySQL table called ranking and this table has got the following fields:
user VARCHAR(12) NOT NULL /* nickname of the user */
mpontos INT NOT NULL /* amount of points per month */
Very simple, huh? Here comes the tricky part... I want to search for a specific user and make a
query that is able to identify the user one position ahead and the user one position behind.
Something like this:
user mpontos
UserA 1532
James Brown 1349
UserB 1229
The most important part is that it cannot be any user with more or less points than James Brown. It
must be exactly the users with the smallest difference to his amount of points. Do you have any
suggestions?
The second part of my problem includes the first one and tries to go in a little bit further...
Using the example above, is it possible to "ask" MySQL for the actual position of James
Brown and the other users on that specific table according to the amount of points? Something like
this:
user mpontos position
UserA 1532 12
James Brown 1349 13
UserB 1229 14
Any suggestions you experts?
Thanks in advance!!!
Fábio Ottolini