Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何修复“意外的'endwhile'”错误?_Php_Html - Fatal编程技术网

Php 如何修复“意外的'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_

当我遇到这个错误,解析错误:语法错误,意外的'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 &rarr;</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 &rarr;</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 &rarr;</a>
<?php } ?>
更多信息:

应该是:在while之后,而不是;:

应该是:过了一会儿,不是;: