你好我得到一个PHP错误“解析错误:语法错误,意外'endwhile'(T_ENDWHILE)在第32行的C:\ wamp \ www \ index.php”关于我做错什么的任何想法?
<?php
include ('includes/db_connect.php');
$query = $db->prepare("SELECT post_id, title, body FROM posts");
$query->execute();
$query->bind_result($post_id, $title, $body);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></head>script>
<![endif]-->
<script scr="http://code.jquery.com/jquery-1.5.min.js"></script>
</head>
<style>
#container{
margin:auto;
width:800px;
}
</style>
<body>
<div id="container">
<?php
while($query->fetch());
?>
<article>
<h2><?php echo $title ?></h2>
<p><?php echo $body?></p>
</article>
<?php endwhile?>
</div>
</body>
</html>
答案 0 :(得分:2)
更改:while($query->fetch());
至:while($query->fetch()):
(从结肠到结肠)