哪里可能出错????在第24行,没有看到任何东西..任何人都可以找出错误?我会非常感激...它说错误在第24行
错误消息
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\database.php on line 24
<?php
$mysqli = new mysqli('localhost', 'root', '', 'test');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$query = "SELECT fname, lname,name FROM persons INNER JOIN foods ON persons.id = food_id";
$result = $mysqli->query($query);
echo "<table>";
echo "<tr>";
echo "<td> <b> First Name </b> </td>";
echo "<td> <b> Last Name </b> </td>";
echo "<td> <b> Food </b> </td>";
echo "</tr>";
while ($row = $result->fetch_assoc()) {
echo "<td> $row['fname'] </td>";
echo "<td> $row['fname'] </td>";
echo "<td> $row['name'] </td>";
}
echo "</tr>";
echo "</table>";
?>
答案 0 :(得分:3)
将循环更改为此
while ($row = $result->fetch_assoc()) {
echo "<td>". $row['fname'] ."</td>";
echo "<td>". $row['fname'] ."</td>";
echo "<td>". $row['name'] ."</td>";
}
答案 1 :(得分:2)
试试这个
echo "<td>" . $row['fname'] . "</td>";
答案 2 :(得分:1)
Read the manual for the correct syntax用于在字符串中嵌入数组值,"$arr['key']"
不是正确的两种方式之一。
要么是
"$arr[key]"
或
"{$arr['key']}"
答案 3 :(得分:1)
您应该在第24行使用此代码
echo "<td> $row[fname] </td>";
echo "<td> $row[fname] </td>";
echo "<td> $row[name] </td>";
答案 4 :(得分:1)
您也可以使用:
while ($row = $result->fetch_assoc()) {
echo "<td>{$row['fname']}</td>";
echo "<td>{$row['fname']}</td>";
echo "<td>{$row['name']}</td>";
}