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);
}
?>
No comments:
Post a Comment