gpt4 book ai didi

php - 如何在一定数量后停止++$i 自动递增

转载 作者:行者123 更新时间:2023-11-30 22:14:07 25 4
gpt4 key购买 nike

我正在为比赛制作这张表,正如您所看到的,我正在从数据库中获取数据,就像从数组中获取数据一样,问题是只有 3 个奖品,大概有 40 个参与者,我想向每个参与者展示到目前为止他赢得的奖品,但在第三名之后我想在名字旁边显示“No Aplica”状态,问题是我无法阻止计数器上升,也无法将其设置为固定数字所以它保持不变在“No Aplica”选项上

<table style="display:inline;" class='table-personal table-striped'>
<thead>
<tr>
<th class="line-header">Posición</th>
<th>Premio</th>
<th>Nombre</th>
<th>Puntos Jul</th>
<th>Puntos Ago</th>
<th>Puntos Sep</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
$e = -1;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$premio=array("$10.000", "$5.000", "$2.000", "No Aplica");
echo "<tr class='posicion'>";
echo "<td class='line-rows'>" . $premio[++$i] . "</td>";
echo "<td>" . $row["nombre"] . "</td>";
echo "<td>" . $row["puntos_julio"] . "</td>";
echo "<td>" . $row["puntos_agosto"] . "</td>";
echo "<td>" . $row["puntos_septiembre"] . "</td>";
echo "</tr>";
if ($i >= 3) {
$i = -1;
}
}
?>
</tbody>
</table>

最佳答案

如果 $i 的值小于 3,则需要增加 $i 的值。否则不需要增加 $i< 的值.

这样做:

<?php
$i = 0;
$e = -1;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$premio=array("$10.000", "$5.000", "$2.000", "No Aplica");
echo "<tr class='posicion'>";
echo "<td class='line-rows'>" . $premio[$i] . "</td>";
echo "<td>" . $row["nombre"] . "</td>";
echo "<td>" . $row["puntos_julio"] . "</td>";
echo "<td>" . $row["puntos_agosto"] . "</td>";
echo "<td>" . $row["puntos_septiembre"] . "</td>";
echo "</tr>";
if ($i < 3) {
$i++;
}
}
?>

关于php - 如何在一定数量后停止++$i 自动递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39044608/

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