获取特定行的索引
I am using a MySQL database to record player highscores on a game I am creating. The MySQL database is being accessed through a PHP file "highscores.php".
我正在使用MySQL数据库记录玩家在我正在创建的游戏中的高分。通过PHP文件“highscores.php”访问MySQL数据库。
The highscores are all recorded inside the database, but I want the actual rank numbers to be implemented by the PHP file. I want to be able to query for the ranking of a specific player, instead of only querying for his/her highscore.
高分都记录在数据库中,但是我希望PHP文件实现实际的排名数字。我希望能够查询一个特定玩家的排名,而不是只查询他/她的高分。
I am using this to get the highscore of my player:
我用这个来获得我的球员的高分:
$username = $_GET["username"];
$checkID = mysql_query("SELECT * from Highscores WHERE Username =
'$username' ORDER BY Score DESC");
$row = mysql_fetch_array($checkID);
echo $row["Score"];
Now to get the ranking of my player amongst all the other players, all I need to do is find the index of the row in question... But how do I do that?
现在要得到我的球员在所有其他球员中的排名,我所要做的就是找到问题所在行的索引……但是我怎么做呢?
Thanks in advance!
提前谢谢!
3 个解决方案
#1
3
You could do it with SQL directly like this:
您可以直接使用SQL来完成如下操作:
SELECT @rownum:=@rownum+1 ‘rank’, h.*
FROM Highscores h, (SELECT @rownum:=0) r
ORDER BY score DESC;
更多相关文章
- 字体图标的引入和通过媒体查询改变导航样式
- HTML样式和常用选择器
- 字体图标的引用和自定义样式/媒体查询的使用
- 数据库的CURD操作、PDO本质与原理的学习
- CSS之伪类选择器和简单盒子简单案例
- 伪类选择器与盒模型常用属性
- 伪类选择器-结构伪类、根据位置选择匹配
- 7.4——常用标签与应用场景之表格与单元格
- css伪类选择器和盒模型