表不显示数组查询中的任何结果

时间:2014-10-23 11:02:26

标签: php mysql

我正在尝试在网页上显示数据库的结果。使用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。这是我的表规格:

enter image description here enter image description here

有人能告诉我为什么我没有得到任何结果吗?

1 个答案:

答案 0 :(得分:0)

更改

while($row = mysqli_fetch_array($result))

while($row = mysqli_fetch_array($results))

您可能在引用$ results变量时输了一个错字。