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;

更多相关文章

  1. 字体图标的引入和通过媒体查询改变导航样式
  2. HTML样式和常用选择器
  3. 字体图标的引用和自定义样式/媒体查询的使用
  4. 数据库的CURD操作、PDO本质与原理的学习
  5. CSS之伪类选择器和简单盒子简单案例
  6. 伪类选择器与盒模型常用属性
  7. 伪类选择器-结构伪类、根据位置选择匹配
  8. 7.4——常用标签与应用场景之表格与单元格
  9. css伪类选择器和盒模型

随机推荐

  1. 天气预报API接口大全
  2. 《Zend studio 12 + UPUPW+PHP5.4开发平
  3. 使用jQuery和ajax更改浏览器地址栏URL,无
  4. php-fpm的两种配置方式
  5. 在通过AJAX响应发送的页面上执行javascri
  6. php中的文件包含
  7. PHP格式化日期,显示“刚刚,几分钟前,几小时
  8. 在多维数组中查找最小值并返回键
  9. PHP Word上的短网址
  10. 一个关于用php输出文件的问题(急)