gpt4 book ai didi

PHP - 表 ID 相同

转载 作者:行者123 更新时间:2023-11-30 22:43:40 28 4
gpt4 key购买 nike

如何将相同的列(在本例中按“级别”排序)放在一起?我正在做一个高分,我从我的数据库中按级别列出它们。如果他们处于同一级别,我希望他们具有相同的 ID。

但是我不想在别人身上显示ID。只有第一个。这是一个例子:

ID - Name - Level
1 - John - 5
2 - David - 4
3 - Josh - 3
- Sam - 3
4 - George - 2

所以我想把它们放在一起,但是如果它们的级别相同,只有第一个显示ID。

我不希望它看起来像:

1 - John - 5
2 - David - 4
3 - Josh - 3
3 - Sam - 3
4 - George - 2

现在,它只是列出每个人,并给每个人一个唯一的 ID。即使他们具有相同的“级别”。我怎样才能解决这个问题?这是我的代码:

<?php
$sql = mysql_query("SELECT * FROM rookstayers ORDER BY level DESC LIMIT 0, 500");
$id = 1;
while($row = mysql_fetch_array($sql)){
$name = $row['name'];
$level = $row['level'];
$world = $row['world'];
$account = $row['accountstatus'];
$status = $row['onlinestatus'];
$onrow = '';
$typeServ = '';

$player_name = urlencode($name);

if ($status == 1){
$status = 'Online';
$onrow = 'online';
} else {
$status = 'Offline';
$onrow = 'offline';
}

if ($account == 'Premium Account'){
$account = 'Premium';
} else {
$account = 'Free';
}

if ($world == 'Aurora' || $world == 'Aurera'){
$typeServ = 'active';
} else {
$typeServ = '';
}

echo "<tr class=" . $typeServ . ">";
echo "<td>" . $id . "</td>";
echo "<td>" . $name . " <a href='http://www.tibia.com/community/?subtopic=characters&name=" . $player_name . "' target='_blank'><img src='../../img/websites/tibia.png' title='Tibia Profile'></a><a href='http://www.pskonejott.com/otc_display.php?character=" . $player_name . "' target='_blank'><img src='../../img/websites/pskonejott.png' title='Pskonejott'></a>" . "</td>";
echo "<td>" . $level . "</td>";
echo "<td>" . $world . "</td>";
echo "<td>" . $account . "</td>";
echo "<td class=" . $onrow . ">" . $status . "</td>";
echo "</tr>";

$id++;
}
echo "</tbody>";
echo "</table>";
?>

最佳答案

您可以为当前级别创建一个临时变量并检查它以查看该 id 是否会显示在输出中。

    $id = 1;
$last_player_lvl = '';
while($row = mysql_fetch_array($sql)){
///....

echo "<tr class=" . $typeServ . ">";
echo "<td>" . ( ($last_player_lvl == $row['level']) ? '' : $id ) . "</td>";
echo "<td>" . $name . " <a href='http://www.tibia.com/community/?subtopic=characters&name=" . $player_name . "' target='_blank'><img src='../../img/websites/tibia.png' title='Tibia Profile'></a><a href='http://www.pskonejott.com/otc_display.php?character=" . $player_name . "' target='_blank'><img src='../../img/websites/pskonejott.png' title='Pskonejott'></a>" . "</td>";
echo "<td>" . $level . "</td>";
echo "<td>" . $world . "</td>";
echo "<td>" . $account . "</td>";
echo "<td class=" . $onrow . ">" . $status . "</td>";
echo "</tr>";
if($last_player_lvl == $row['level']){
$id = $id;
}else{
$id++;
}
$last_player_lvl = $row['level'];
//....

关于PHP - 表 ID 相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30281403/

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