gpt4 book ai didi

php - 排名/天梯系统

转载 作者:行者123 更新时间:2023-11-29 09:02:27 28 4
gpt4 key购买 nike

我正在尝试创建一个排名/阶梯系统,其中排名最高的氏族 (1) 应位于顶部,排名为 2 的氏族应位于顶部,依此类推。但我无法让它工作......我尝试了不同的方法:

PHP:

$sql = mysql_query("SELECT * FROM clans ORDER BY rating DESC");
while($row=mysql_fetch_array($sql))
{
$totalclans = $row['id'];
}

$clans = 1;
$clansnumber = $totalclans;

while($clans <= $totalclans)
{
$sql2 = mysql_query("SELECT * FROM clans WHERE id='$clansnumber'");
while($row=mysql_fetch_array($sql2))
{
$name = $row['name'];
}

$sql2 = mysql_query("SELECT COUNT(*) AS totalmembers FROM members WHERE clan='$name'");
while($row=mysql_fetch_array($sql2))
{
$totalmembers = $row['totalmembers'];
}

$sql2 = mysql_query("SELECT * FROM clans WHERE id='$clansnumber'");
while($row=mysql_fetch_array($sql2))
{
echo "<div class='newestmemberusername'><a href='clan.php?clan=" . $row['name'] . "'>" . $row['name'] . ":</a></div>";
echo "<table class='profileinfo' cellpadding='5' cellspacing='0' border='0'>";
echo "<tr><td rowspan='4' style='border:none;'><div class='rankbox'>" . $row['rating'] . "</div></td></tr>";
echo "<tr><td style='" . $firstrowleft . " width: 200px;'>Members:</td><td class='profileinfosecondrow' style='" . $firstrowright . "'>" . $totalmembers . "</td></tr>";
echo "<tr><td style='" . $color2 . " width: 200px;'>Victories:</td><td class='profileinfosecondrow' style='" . $color2 . "'>" . $row['victories'] . "</td></tr>";
echo "<tr><td style='" . $lastrowleft1 . " width: 200px;'>Losses:</td><td class='profileinfosecondrow' style='" . $lastrowright1 . "'>" . $row['losses'] . "</td></tr>";
echo "</table>";

$clans ++;
$clansnumber --;
}
}

echo "</div>";
echo "<div class='contentboxbodybottom'></div>";
}

不幸的是,它只显示所有氏族,而不是按照等级排序。我尝试将 id 更改为排名并更改它,以便它首先检查排名 1,然后检查排名 2,直至排名 10(最大排名),但它仍然只是按我不这样做的顺序显示所有部落我不想这样。

最佳答案

您能解释一下为什么使用大量 while 语句

试试这个

 $sql = mysql_query("SELECT * FROM clans ORDER BY rating DESC");
while($row=mysql_fetch_array($sql)) {
$totalclans = $row['id'];
$name = $row['name'];

echo $id.'<br/>'.$name;


}

如果您遇到任何问题,请告诉我,然后尝试详细说明您实际想要从数据库中获取的内容

关于php - 排名/天梯系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203433/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com