创建一个排行榜,我将如何去显示排名/位置? [英] Creating a leaderboards, how would I go about displaying rank/position?

查看:148
本文介绍了创建一个排行榜,我将如何去显示排名/位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建排行榜,其中显示以下内容:排名,用户名,分数

I am creating a leaderboards which will display the following: Rank, Username, Score

我目前拥有表格,它将显示用户名和分数一个MySQL表,我只是想知道如何去显示每个用户的排名,数字1是最高分的用户然后降序。

I currently have the table to it will display Username and Score from the data in a mysql table, I am just wondering how would I go about displaying a rank for each user, number 1 being the user with the highest score then descending.

谢谢! / p>

Thanks!

推荐答案

我建议阅读 PHP / MySQL

HTML标题:打开你的表格, p>

HTML Header: Open your table, create your headers

<table>
    <tr>
        <td>Rank</td>
        <td>User</td>
        <td>Score</td>
    </tr>

PHP:动态生成每个用户的行

PHP: Dynamically generate the rows for each user

    <?php

        $result = mysql_query("SELECT user, score FROM leaderboard ORDER BY score DESC");
        $rank = 1;

        if (mysql_num_rows($result)) {
            while ($row = mysql_fetch_assoc($result)) {
                echo "<td>{$rank}</td>
                      <td>{$row['user']}</td>
                      <td>{$row['score']}</td>";

                $rank++;
            }
        }
    ?>

HTML页脚:需要关闭表格

</table>

这篇关于创建一个排行榜,我将如何去显示排名/位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆