I'm following a tutorial on how to create a dynamic blog system when I ran into this error, Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE), expecting end of file.
<?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>