hya all im following a tutorial and i got the following code of which im getting the following error

Parse error: syntax error, unexpected T_WHILE in /home/letsswin/public_html/TESTFILES/blog/index.php on line 36

can anyone tell me what is causing this

    <?php 
//connect to the database
include('includes/db_connect.php');
$query = $db->prepare("SELECT post_id, title, LEFT(body, 100) AS body, category FROM posts INNER JOIN categories ON categories.catergory_id=posts.catergory_id order by post_id desc");
$query->execute();
$query->bind_result($post_id, $title, $body, $category);
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="Kevin Robinson" />
    <title>Blog System - Home</title>
    <!--[if lt IE 9]>
    <script src="http://code.jquery.com/jquery=1.5.min.js"></script>
    <![endif]-->
</head>
<style>
#container{
    margin: auto;
    width: 800px;
}
</style>
<body>

<div id="container">
   <?php
       while($query->fetch());
       $lastspace = strrpos($body, ' ');
   ?>
   <article>
   <h2><?php echo $title ?></h2>  
   <p><?php echo substr($body, 0, $lastspace)."<a href='post.php?id=$post_id'>..</a>"?></p>
   <p>category: <?php echo $category?></p> 
   </article>
   <?php end while ?> 
</div>
</body>
</html>

if anyone can help would be much appreicated x

Try:

   <?php
       while($query->fetch()):
       $lastspace = strrpos($body, ' ');
   ?>
   <article>
   <h2><?php echo $title ?></h2>  
   <p><?php echo substr($body, 0, $lastspace)."<a href='post.php?id=$post_id'>..</a>"?></p>
   <p>category: <?php echo $category?></p> 
   </article>
   <?php endwhile; ?> 

done that now im getting Fatal error: Call to a member function execute() on a non-object in /home/letsswin/public_html/TESTFILES/blog/index.php on line 5 hun
see code below:)X

<?php 
//connect to the database
include('includes/db_connect.php');
$query = $db->prepare("SELECT post_id, title, LEFT(body, 100) AS body, category FROM posts INNER JOIN categories ON categories.catergory_id=posts.catergory_id order by post_id desc");
$query->execute();
$query->bind_result($post_id, $title, $body, $category);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.