Php 如何修复“意外的'endwhile'”错误?
当我遇到这个错误,解析错误:语法错误,意外的'endwhile'T_endwhile,预期文件结束时,我正在学习如何创建一个动态博客系统Php 如何修复“意外的'endwhile'”错误?,php,html,Php,Html,当我遇到这个错误,解析错误:语法错误,意外的'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_
<?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>
您的代码中有一个输入错误。带有endwhile的while语句应以冒号结尾:
<?php while($query->fetch()): ?>
<?php while($query->fetch()): ?>
或者,您可以将代码用花括号括起来:
<?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的while语句应以冒号结尾:
<?php while($query->fetch()): ?>
<?php while($query->fetch()): ?>
或者,您可以将代码用花括号括起来:
<?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 } ?>
更多信息:应该是:在while之后,而不是;:
应该是:过了一会儿,不是;: