以最高级别订购MYSQL PHP(Runescape Clan Highscores)

时间:2017-07-17 19:08:22

标签: php mysql

已更新以提供更好的解释:

我正试图在一个名为runescape的游戏中为我的战队创建一个高分榜功能,但我不知道如何按照&#34;总水平排序排行榜&#34; < / p>

Working Demo without sorting by total level

例如,silenthawk应该是顶级的,因为他总共有1,941。我有一个名为rsusers的表,列 id,rank和playername

我正在做一个sql查询,让所有来自战队的人通过使用我在github(linked here)上找到的名为oldschoolhiscore.php的页面从runescape网站上取得高分 - 我认为我所要做的就是编辑此页面,按照总水平排序&#39;但我不确定?

这里有一个非常简单的演示和代码:

Demo here

代码:

        <?php

    require 'OldSchoolHiscore.php';


    $dbhost = 'localhost';  
    $dbuser = 'xxxx';  
    $dbpass = 'xxxxxxxxx';  
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');  
    $dbname = 'xxxxxx';  
    $connection = mysql_select_db($dbname);  


    $sql = "SELECT * FROM rsusers";  
    $rs_result = mysql_query ($sql);  


    ?>  



        <table class="table table-striped table-list-search">
            <thead>
                <tr>
                    <td>Name</td>
                    <td>Level</td>
                </tr>
            </thead>

            <tbody>


            <?php  

            while ($row = mysql_fetch_assoc($rs_result)) { 



                $hs = new OldSchoolHiscore($row['username']);


                $total_level = $hs->getSkillLevel('overall');

                echo "<tr>";

                echo "<td>".$row['username']."</td>";
                echo "<td>$total_level</td>";


                echo "</tr>";




            }

            ?>  

    </tbody>
    </table>

SQL

    INSERT INTO rsusers 
(username, clanrank)
VALUES 
('Dwh_Hunters', 'lieutenant'),
('SilentHawk', 'general'),
('Sir Novel', 'lieutenant'),
('Ryuk Yagami', 'general');

1 个答案:

答案 0 :(得分:0)

使用 ORDER BY

尝试

 $sql = ('SELECT * FROM rsusers ORDER BY level DESC');