0

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

2
Contributors
2
Replies
21
Views
2 Years
Discussion Span
Last Post by janicemurby
0

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; ?> 
0

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);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.