Re: number on the quene, or how to get rank?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You could try something like this perhaps...

SELECT score FROM highscores WHERE name = 'userD'

then use the result of that to do this:

SELECT COUNT(*) FROM highscores WHERE score > 2

rank would then be the result of the above query plus one.

-philip

On Tue, 5 Apr 2005 emre@xxxxxxxxx wrote:

hi everyone,

I' ve a table named as 'highscores', inserting result scores of a game and players name(each player can only play once)  what I want to do is to get the "current rank" of a player over a listing of all rows ordered by scores desc.


id -name - score 1 - userA - 8 2 - userB - 3 3 - userC - 10 4 - userD - 2 5 - userE - 7


here is how I figured out this thing:


$sql=mysql_query(SELECT userD FROM highscores ORDER BY score DESC); $i=1; while($scorelist=mysql_fetch_array($sql)) { if($scorelist[name]=='userD') echo "your rank is: $i "; $i++; }


how can I get a specific row's "formatted no" through all affected rows? Is there a MySQL command doing this job that i am unaware of?

thx  in adv.




-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux