简体   繁体   English

回显查询结果的每条记录

[英]Echo each record of a query result

I'm attempting to extract some data from a database and echo each result. 我试图从数据库中提取一些数据并回显每个结果。 The code below is code that I took from a textbook and then tried to modify to fit my own website that is hosted locally. 下面的代码是我从教科书中获取的代码,然后尝试对其进行修改以适合本地托管的我自己的网站。 I cannot see where I'm going wrong, no error messages are shown, just a blank screen when I run the scrip. 我看不到我要去哪里,没有错误消息显示,当运行脚本时只有一个空白屏幕。

<?php #script 9.4 view top 5 recipients
// This script exctracts data from db and then displays each record in a table

    DEFINE('SYSPATH','FOO');

    require '../application/config/database.php';

    require 'mysqli_connect.php';

    $q = "SELECT alert_recipient as NAME
          FROM alert
          LIMIT 5;
          ";

    $r = mysqli_query($dbc,$q);

    // $dbc database connection comes from required mysqli_connect.php       

    if($r) 
        {

        while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

            echo $row['name'];
        }

        }


    else {
        echo "<p>ERROR</p>".mysqli_error($dbc);
        }

?>

The code looks okay except for your echo $row['name']; 该代码看起来还可以,除了您的echo $row['name']; , note that you are selecting NAME , uppercase. ,请注意,您选择的是大写的NAME

Change your echo statement to be: 将您的echo语句更改为:

echo $row['NAME'];

because field names quoted within $row array are case sensitive. 因为$row数组中引用的字段名称区分大小写。

(Can't comment yet) (尚无法评论)

Maybe the script works but there is no results to display. 脚本可能有效,但没有结果可显示。 Check your database. 检查您的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM