Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

High score position

Codes here !

Moderators: macek, egami, gesf

High score position

Postby pauberson » Fri Nov 01, 2002 5:48 am

Hi,

I want to know the position of a entry in a highscore table but the only way i can think of doing this is "SELECT * from entries ORDER BY score DESC" and then loop though all the entries in php until i find the record i want.

It seems like there ought to be a better way to do this especially as the number of records increases. Can you find this position information directly in the SQL or is there a php function that will be better than going through all the records?

Thanks,
Pascal.
pauberson
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Nov 01, 2002 5:35 am

Postby DoppyNL » Fri Nov 01, 2002 6:10 am

Once you know the score of the entry you can determine its "rank" by selecting all records wich have a better score.
The number of records that comply with that query are in front of that score.

example:
rank..score
1..10
2..8
3..5
3..5
3..5
6..3
7..2
7..2

When you want to know the position of score "5", you find out that there are 2 records in front of that, 2 + 1 = 3 -> position 3.

I think you can build the query yourself.

Greetz Daan
DoppyNL
 

Postby pauberson » Fri Nov 01, 2002 6:47 am

Great, exactly what i was after. :D

Thanks,
Pascal.
pauberson
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Nov 01, 2002 5:35 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron