<?php
$conn= new mysqli("localhost", "my_user", "my_password", "world"); //changed for the sake of this question
$query = "select * from user;";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
echo '<dt>';
foreach($row as $field) {
echo'<dd>'.$row['FirstName'].'</dd>';
}
echo '</dt>';
}
?>
我只是想在数据库atm中回显一列,它似乎没有显示任何内容。我想知道是否有人可以帮助我? 我收到此错误
[2012年8月23日16:14:04] PHP致命错误:在第51行的/devel/cgreenheld/projects/Asgn1final/admin.php中调用非对象的成员函数fetch_assoc() -bash-3.2 $
答案 0 :(得分:0)
尝试:
$conn= new mysqli("localhost", "my_user", "my_password", "world");
$query = "select * from user";
$result = $conn->query($query);
echo '<dt>';
while ($row = $result->fetch_assoc()) {
echo '<dd>'.$row['FirstName'].'</dd>';
}
echo '</dt>';
答案 1 :(得分:0)
首先,你不需要“;”在您的查询中。其次,我认为您必须确保您的数据库连接处于活动状态,并且查询返回任何内容。
答案 2 :(得分:0)
尝试连接和查询..
$conn = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
echo "Connect failed: ".mysqli_connect_error()."\n";
exit();
}
$query = "SELECT * FROM `user`";
if ($result = $mysqli->query($query)) {
echo '<dt>';
while ($row = $result->fetch_assoc()) {
echo'<dd>'.$row['FirstName'].'</dd>';
}
echo '</dt>';
$result->free();
} else {
echo $mysqli->error;
}
$mysqli->close();