我通过PHP / MySQL输出了一些数据。它只是一个与某个字符串对应的中文字符列表。
$i = 0;
while ($i <= $x) {
echo "<div class=\"char-option\"><a href=\"character.php?char=" . $results[$i]['id']. "\">" . $results[$i]['mainchar'] . "</a></div>";
$i++;
}
我有另一行,其中有一个角色排名,大约20%的角色有排名。我想:
提前致谢。
答案 0 :(得分:1)
步骤1:确定,哪个角色排名最高。
$high = -1, $hrank = 0;
for($i = 0; $i <= $x; ++$i) {
if(isset($results[$i]['rank']) && $hrank < $results[$i]['rank']) {
$high = $i;
$hrank = $results[$i]['rank'];
}
}
步骤2:使用具有最高角色排名的信息,我们可以确定谁获得正常班级以及谁获得额外班级。
for($i = 0; $i <= $x; ++$i) {
$class = "char-option"; //Default class
if($i == $high) $class .= " char-common"; //Adds the second class for the highest ranked character.
echo "<div class=\"$class\"><a href=\"character.php?char=" . $results[$i]['id']. "\">" . $results[$i]['mainchar'] . "</a></div>";
}
$high
中的-1确保该类不会被更改,除非列表中某处有排名。
答案 1 :(得分:0)
在结果中设置排名并以此方式执行。
$i = 0;
while ($i <= $x) {
if ($results[$i]['highest_ranking'] == 1) {
$class = "char-option char-common";
} else {
$class = "char-option";
}
echo "<div class=\"$class\"><a href=\"character.php?char=" . $results[$i]['id'] . "\">" . $results[$i]['mainchar'] . "</a></div>";
$i++;
}