简体   繁体   中英

what is the best practice leaderboard with php, mysql, memcached?

Recently I have developed mobile game (LAMP + memcached).

The game has player's score table. The table has member_id , name , score column.

I want to show leaderboard (global rank) to our user.

Just query SELECT * FROM score ORDER BY score DESC , and show the resultset.

But I don't think it is good way. If users reach 20 million, this query seem to be terrible. What is the best practice in this case? Could you give me some advice?

And how can I check specific user's rank? I want to show each user rank where they are.

Well, you don't want to display millions of users on the leader board do you?

SELECT * FROM score ORDER BY score DESC LIMIT 10

Would select top 10

Further, if you want to display a users rank on for instance a profile page this should do:

SELECT COUNT(*) + 1 AS rank FROM score WHERE score > (SELECT score FROM score WHERE member_id = :member_id);

You simply add the current users member_id to the last query and it will count all rows ahead of him and add 1 to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM