K, I have one issue about PHP. I'm trying to make a highscore for my game that has levels and XP.
我有一个关于PHP的问题。我正在努力为我的游戏的等级和XP做一个高分。
My issue is pretty simple, I want to order it by total level, so that the people with the highest total level come up as first, second, third, etc. But I also want it to be ordered by xp, so that if they have the same total level, than the person with the highest xp will be shown first, instead of it being just random.
我的问题很简单,我想订的总水平,所以人们总水平最高的为第一,第二,第三,等等。但我也想要下令xp,那么,如果他们有相同的总水平,比最高的人xp将显示第一,相反的它仅仅是随机的。
This is what I have so far for ordering by level, but I don't know how to make it check for the xp.
这是我目前为止按级别排序的内容,但我不知道如何让它检查xp。
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM skillsoverall"),0) or die(mysql_error());
$from = (isset($_GET["from"]) && is_numeric($_GET["from"]) && $_GET["from"] < $count) ? $_GET["from"] : 0;
$query = mysql_query ("SELECT * FROM skillsoverall ORDER BY lvl DESC limit $from, $ppls_page") or die(mysql_error());
$i = $from;
while($row = mysql_fetch_array($query)){
$i++;
if($i < $top_hiscore) {
if($i & 1) {
echo '<tr class="row row1">
<td class="rankCol"><span>'.$i.'</span></td>
<td class="nameCol"><span><a href="'.$website.'/'.$pers.'?name='.$row["playerName"].'" target="_self">'.BBCode($row["playerName"]).'</a></span></td>
<td class="lvlCol">'.dots($row["lvl"]).'</td>
<td class="xpCol">'.dots($row["xp"]).'</td>
</tr>
';
} else {
echo '<tr class="row row2">
<td class="rankCol"><span>'.$i.'</span></td>
<td class="nameCol"><span><a href="'.$website.'/'.$pers.'?name='.$row["playerName"].'" target="_self">'.BBCode($row["playerName"]).'</a></span></td>
<td class="lvlCol">'.dots($row["lvl"]).'</td>
<td class="xpCol">'.dots($row["xp"]).'</td>
</tr>
';
I'm not sure where to go from here, any help?
我不知道从这里到哪里去,有帮助吗?
1 个解决方案
#1
0
Just do it in your query right off the bat:
直接在你的查询中做吧:
SELECT * FROM skillsoverall ORDER BY lvl DESC, xp desc
SQL will allow multiple columns in the order by clause. In this case, it will now return data sorted by highest to lowest level and where there is more than one row with the same level, it sorts the data from highest to lowest XP. It will also work consistently using the limit
clause.
SQL将允许order by子句中的多个列。在这种情况下,它将返回按最高到最低级别排序的数据,并且在同一级别上有多个行,从最高到最低的XP中对数据进行排序。它还将持续使用limit子句。
#1
0
Just do it in your query right off the bat:
直接在你的查询中做吧:
SELECT * FROM skillsoverall ORDER BY lvl DESC, xp desc
SQL will allow multiple columns in the order by clause. In this case, it will now return data sorted by highest to lowest level and where there is more than one row with the same level, it sorts the data from highest to lowest XP. It will also work consistently using the limit
clause.
SQL将允许order by子句中的多个列。在这种情况下,它将返回按最高到最低级别排序的数据,并且在同一级别上有多个行,从最高到最低的XP中对数据进行排序。它还将持续使用limit子句。