分数页面上的逻辑是什么:
当前用户在所有玩家中的顺序(如#115):MySql SELECT for all users ORDER BY Score DESC 然后检查当前用户在哪里?
更好的两个分数:获取当前用户,然后 SELECT LIMIT 2 WHERE Score > "$currentuserscore"?
减去两个分数:获取当前用户,然后 SELECT LIMIT 2 WHERE Score < "$currentuserscore"?
我觉得这个有很多问题,还有其他办法吗?
最佳答案
对于选项 1:
select count(1) as count from users where score>=$user_score
这应该会给你这个人的等级。如果您担心多个人与当前用户具有相同的分数,请更改 >=
到 >
然后你可以将结果加 1。
对于选项 2 和 3:
select * from users where score>$user_score order by score asc limit 2
select * from users where score<$user_score order by score desc limit 2
或者,一旦您获得第一个查询的排名,您就可以在一个查询中获得所有 5 个(之前的 2 个、之后的 2 个以及当前用户):
$start = $user_rank - 2;
$query = "select * from users order by score asc limit {$start},5";
或者,如果您不希望包含当前用户或与当前用户具有相同分数的任何人,您可以执行以下操作:
$start = $user_rank - 2;
$query = "select * from users where score!=$user_score order by score asc limit {$start},4";
关于PHP MySql 游戏比分页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14284232/