Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何使用以下方法获得写入我页面的玩家的排名:
$res = $con->query("SELECT * FROM hiscores ORDER BY `0` DESC LIMIT 50");
我的页面上有我的玩家列表,按他们在第 0 列中的值组织。我如何根据 ORDER BY 获得玩家的排名?
你应该ORDER BY score DESC
ORDER BY score DESC
然后是这样的:
foreach ($res as $player) { echo "Rank #" . (intval(key($player)) + 1) . " for player " . $player['playerName'] . "<br>" . PHP_EOL; }
逻辑是获取元素的索引并将其加一
$player[0] = 1 $player[1] = 2 ...