当我遇到此错误(解析错误)时,我正在跟踪有关如何创建动态博客系统的教程:语法错误,意外的“ endwhile”(T_ENDWHILE),期望文件结尾。
<?php
//connect to DB
include('includes/db_connect.php');
$query = $db->prepare("SELECT post_id, title, body FROM posts");
$query->execute();
$query->bind_results($post_id, $title, $body);
?>
<!DOCTYPE html>
<html lang="en">
<body>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<br><br>
<h1 class="mt-4 mb-3" >News</h1>
<hr>
<div class="row">
<!-- Blog Entries Column -->
<div class="offset-lg-2">
<!-- Paste New Entries Here -->
<!-- Blog Post -->
<div class="card mb-3">
<div class="card-body">
<?php while($query->fetch()); ?>
<h2 class="card-title"><?php echo $title ?></h2>
<p class="card-text"><?php echo $body ?></p>
<a class="btn btn-CMD" href="#">Read More →</a>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
您的代码中有错字。具有while
的{{1}}语句应以冒号结尾:
endwhile
或者,您也可以将代码放在大括号中
<?php while($query->fetch()): ?>
答案 1 :(得分:2)
在:
之后应该有while
,而不是;
:
<?php while($query->fetch()): ?>