Web Hosting Talk







View Full Version : How to figure out what position a record is in the database?


monkey junkie
07-29-2007, 06:53 PM
Hello

I hope someone can help me with this.

I am working on a website which allows people to vote users up and down.

You can see the website here: http://www.babes.ie (http://www.babes.ie/)

The way I figure out who is #1 and #2 etc. is simply by sorting the SQL results in desc order.

However I would like to be able to figure out what position each user is on the fly. For example, if the user "lisam03" wanted to know what position she is in, I would like to be able to tell her she is #6. At the moment I cannot do this. I can only tell she is #6 by displaying the results for everyone and finding her position.

Does anyone know any way I can find out, on the fly, what position a record is in a database?

Any help greatly appreciated.

Thanks

foobic
07-29-2007, 07:21 PM
1 + result of "SELECT COUNT(*) FROM table WHERE score > thisusersscore"