php while循环后输出停止

aan*_*s77 3 php loops execution while-loop

我有以下PHP代码:

echo "<div style='float:left;'>";
echo "<table>";
echo "<tr>";
echo "<th></th>";
echo "<th colspan='4'>Laks beholdt</th>";
echo "</tr>";
echo "<tr>";
echo "<th>Uke</th>";
echo "<th>&lt;3 kg</th>";
echo "<th>3-7 kg</th>";
echo "<th>&gt;7 kg</th>";
echo "<th>Totalt</th>";
echo "</tr>";

while ($row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error()))
{
   echo "<tr>";
   echo "<td>" . $row['Uke'] . "</td>";
   echo "<td style='text-align:right; padding-right:10px;'>" . number_format($row['SumSmall'], 1,
      ",", " ") . " kg</td>";
   echo "<td style='text-align:right; padding-right:10px;'>" . number_format($row['SumMedium'], 1,
      ",", " ") . " kg</td>";
   echo "<td style='text-align:right; padding-right:10px;'>" . number_format($row['SumLarge'], 1,
      ",", " ") . " kg</td>";
   echo "<td style='text-align:right; padding-right:10px;'>" . number_format($row['SumVekt'], 1, ",",
      " ") . " kg</td>";
   echo "</tr>";
}

echo "</table>";
echo "</div>";
Run Code Online (Sandbox Code Playgroud)

我得到了while循环的预期输出,但是我的表和div的结束标记 - 或者任何其他输出 - 都没有显示.我没有收到任何错误消息,我在html中看不到任何错误.我试过用数字而不是关联来引用数组,但我得到了相同的结果.

我已经写了一百个类似的循环没有错误,但我在这里没有想法:/

jpr*_*itt 6

or die()声明导致它停止执行.什么时候$row = mysql_fetch_array($result, MYSQL_ASSOC)应该停止循环,它会击中它die().由于没有错误,因此不会打印任何内容mysql_error()

echo "Before loop\n";

$x = 1;
while($foo = bar($x) or die('Died')) {
    echo $x++, "\n";
}

echo "After loop\n";

function bar($x) {
    if($x < 5) {
        return $x;
    }
    return false;
}

//outputs:
//Before loop
//1
//2
//3
//4
//Died
Run Code Online (Sandbox Code Playgroud)

键盘版