【发布时间】:2018-08-28 14:01:32
【问题描述】:
我做错了什么?
这是我的代码:
<?php
$db=mysqli_connect("xxxxxx","xxxxxxx","","xxxxxxx");
$sql="SELECT* from flyreise";
$result=mysqli_query($db,$sql);
echo "<table>";
echo "<tr>";
echo "<th></th>";
echo "</tr>";
echo "<tr>";
$countRows=mysqli_affected_rows($db);
for($i=0;$i<$countRows;$i++){
$row=mysqli_fetch_array($result);
echo "<td><strong>From:</strong>".$row["fra"]." <br><strong>To:</strong> ".$row["til"]." <br><strong>Date:</strong> ".$row["dato"]." <br><strong>Clock:</strong> ".$row["klokkeslett"]."</td>";
echo "<td></td>";
echo "<td></td>";
}
echo "</tr>";
echo "</table>";
?>
【问题讨论】:
-
执行SQL语句后检查错误
-
也许您的数据库中有一个空行?
-
看起来更像是最后一行,而不是第一行。尝试
var_dump($row);看看它是否显示任何内容。此外,不要使用mysqli_affected_rows和for($i=0;$i<$countRows;$i++),最好将循环更改为使用while($row = mysqli_fetch_array($result)) {。 -
@aynber 我试过了,但它只是隐藏了最后一行和你看到的粗体文本。我知道我在数据库中有 6 行,但现在只显示 5 行。
-
可以显示数据库的内容吗?准确确定缺少哪一行。