1
在我確定的其他許多問題中,$ result變量未被識別(出現「致命錯誤:調用非成員函數fetch_assoc()對象「),我不知道爲什麼。任何幫助,將不勝感激。代碼如下:
<html>
<body>
<?PHP
$db = new mysqli('localhost', 'root', '', 'edumacation');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$result = <<<SQL
SELECT *
FROM `student`
WHERE `id` = 1
SQL;
while($row =
$result->fetch_assoc()){
echo "<table border='1'><tr><th>Name</th><th>Grade</th><th>Favorite Teacher</th><th>Date Enrolled</th></tr>";
echo "<tr><td>" . $row['first_name'] . "</td><td>" . $row['grade'] . "</td><td>" . $row['fav_teacher'] . "</td></tr>" . $row['enrolled'] . "<br />";
echo "</table>";
}
?>
</body>
</html>