PHP:为什么我会在第38行遇到语法错误,意外的'endwhile'(T_ENDWHILE)?我正在尝试用php和mysql第一次创建一个论坛,我不确定我的代码有什么问题。
<?php
session_start();
require"db_connect.php";
$sql = "SELECT forum_id, forum_name FROM forum_tbl";
if ($query = $db->prepare($sql)){
$query->bind_result($f_id, $f_name);
$query->execute();
$query->store_result();
}else{
echo $db->error;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Forum</title>
<meta/>
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<div class="content">
<table align="center" width="80%">
<?php
if($query->num_rows !==0)
while($row = $query->fetch())
?>
<tr>
<td><a href="forum.php?id=<?php echo $f_id?>"><?php echo $f_name;?> </a></td>
</tr>
<?php endwhile; endif;?>
</table>
</div>
</div>
</body>
</html>
答案 0 :(得分:4)
:
和if
错过了while
。它应该是
if($query->num_rows !==0):
while($row = $query->fetch()):
请参阅最后的:
?