我正在尝试在网页上显示数据库的结果。使用this example,我在下面提出了这段PHP代码:
<?php
$con=mysqli_connect("217.199.187.70","cl52-domains","######","cl52-domains");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$results = mysqli_query($con, "SELECT * FROM domains");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Domain</th>
<th>Address</th>
<th>Price</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['domain_name'] . "</td>";
echo "<td>" . $row['domain_address'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
但是,当我刷新我的网页时,它显示表头(没有错误),但结果为0。这是我的表规格:
有人能告诉我为什么我没有得到任何结果吗?
答案 0 :(得分:0)
更改
while($row = mysqli_fetch_array($result))
要
while($row = mysqli_fetch_array($results))
您可能在引用$ results变量时输了一个错字。