从数据库中获取玩家排名
我有一个 RuneScape 私人服务器,它将玩家分数存储在数据库中。 高分加载玩家的分数并将其放入表格中。
但现在是我无法解决的更困难的部分:
我想显示玩家的排名。比如:‘攻击等级:44,排名第12’。因此它必须找到用户的排名。
我怎样才能让它发挥作用?我用谷歌搜索了两天,没有找到任何东西。
I have a RuneScape private server, which stores the player scores in a database.
The highscores load the player's scores and put them into a table.
But now comes the harder part I can't fix:
I want to display the rank of the player. Like: 'Attack level: 44, ranked 12'. So it has to find the rank the user has.
How can I get this to work? I googled for 2 days now, I did not find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道是否有办法使用相同的查询来实现此目的。
您可以进行另一个查询,例如:
pos =
select count(*) fromplayers where Attack > 44 + 1
此查询将返回排名高于某人的玩家数量。 “加一”部分是让排名从 1 开始(因为第一个排名不会有任何人排名在他之上)。
例如,如果表格为:
pos(3) = 1(只有玩家 2 排在上面)+ 1 = 2
I don't know if there's a way to achieve this using the same query.
You could make another query like:
pos =
select count(*) from players where attack > 44
+ 1This query would return the number of players ranked above someone. The "plus one" part is to make the rank start at 1 (because the first one won't have anyone ranked above him).
For example, if the table is:
pos(3) = 1 (only player 2 is ranked above) + 1 = 2
您(可能)可以创建一个显示每个玩家得分的视图。沿着这些思路的一些东西可能会起作用。
这将为您提供每个玩家的一行以及他们的总得分。有了这个观点,排名就很简单了。
该查询将返回分数高于player_id = 1的玩家数量。
当然,如果您在运行查询之前知道玩家的分数,则可以将该分数作为参数传递。只要该列被索引,运行速度就会快得多。
You can create a view (probably) that shows every players score. Something along these lines might work.
That will give you one row per player, with their total score. Having that view, the rank is simple.
That query will return the number of players having a higher score than player_id = 1.
Of course, if you know your player's score before you run the query, you can pass that score as a parameter. That will run a lot faster as long as the column is indexed.