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

标签 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 个结果。这是我的 table 规范:

enter image description here enter image description here

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

最佳答案

改变

while($row = mysqli_fetch_array($result))

while($row = mysqli_fetch_array($results))

您可能在引用 $results 变量时犯了一个拼写错误。

关于php - 表不显示数组查询中的任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26526674/

相关文章:

php - 找不到类 PDO - 刚刚升级到 PHP 5.6 (Debian Wheezy)

php - 为什么 PHP 的 empty() 函数在 CakePHP 2 中不能按预期与 $this->data 一起工作?

php - 注销在 codeigniter 中不起作用

mysql - 获取多个条件下的多个计数

mysql - 无法从 Google App 引擎 SQLAlchemy 连接到 RDS MySQL(未知主机错误)

php - mysql (php) 上的时间戳问题

php - 使用bindValue进行PDO调试更新查询

PHP/MYSQL 着色名称

PHP MySQL 项目类别

java - 使用 MySQL 的登录/注册 Servlet