RES: [PHP-DB] Creating a ranking

From: Date: Tue, 16 Jan 2001 12:59:40 +0000
Subject: RES: [PHP-DB] Creating a ranking
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-5899@lists.php.net to get a copy of this message
hello, and happy new year to you too. yes there is a way. it called a cursor in most db systems (but i don't the term around recently). use a counter for your result set fetching loop. this counter can be used as your cursor. use the mysql_field_seek function to position the cursor anywhere within the result set. your next mysql_fetch_row will be at the position you specify in mysql_field_seek. you should add "ORDER BY mpontos" to your query in order for it to work. rds mauricio portasio # -----Mensagem original----- # De: Fabio Ottolini (EDB) [mailto:fabio.ottolini@edb.ericsson.se] # Enviada em: Tuesday, January 16, 2001 9:51 AM # Para: 'php-db@lists.php.net' # Assunto: [PHP-DB] Creating a ranking # # # 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 #

« previous php.db (#5899) next »