Re: [PHP-DB] Creating a ranking

2001-01-18 Thread Stas Trefilov

Hello, "Fabio Ottolini (EDB!
You wrote:

> 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?

Use ABS() function to find the smallest  difference between 
the values, ORDER BY ASC(mpontos - )

-- 
Piloteers do it on the road


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RES: [PHP-DB] Creating a ranking

2001-01-16 Thread portasio

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:[EMAIL PROTECTED]]
# Enviada em: Tuesday, January 16, 2001 9:51 AM
# Para: '[EMAIL PROTECTED]'
# 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 153212
# James Brown   134913
# UserB 122914
#
# Any suggestions you experts?
#
# Thanks in advance!!!
#
# Fábio Ottolini
#


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Creating a ranking

2001-01-16 Thread Fabio Ottolini (EDB)

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:

usermpontos
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:

usermpontos position
UserA   153212
James Brown 134913
UserB   122914

Any suggestions you experts?

Thanks in advance!!!

Fábio Ottolini