Page 1 of 1

Unexpected Bracket?

Posted: Fri Dec 12, 2008 3:23 am
by millsy007
I am getting the error:
Parse error: syntax error, unexpected ')' in /home/beachh/public_html/test.php on line 141

But in my code all of the brackets seem to match / be valid :

Code: Select all

 
<?php
 
$query = ("
   SELECT 
      post_date, 
      post_title, 
      post_content, 
      guid 
   FROM 
      `wp_posts` 
   ORDER BY 
      post_date DESC 
   LIMIT 
      0,5");
$result = mysql_query($query);
foreach ($post = mysql_fetch_object($result)) {
   ?>
   <div class="post">
      <div class="post_title">
         <a href="<?= $post->guid ?>"><?= $post->post_title ?><span class="pdate"><?= $post->post_date ?></span></a>
      </div>
      <div class="post_content"><?= $post->post_content ?></div>
   </div>
   <?
}
?>
 
The error is pointing to foreach ($post = mysql_fetch_object($result)) { but to me this seems syntactically correct? Am I missing something?

Re: Unexpected Bracket?

Posted: Fri Dec 12, 2008 3:44 am
by jaoudestudios
Your foreach is wrong. That is not how you do a foreach, I think you want to do a while instead.

Re: Unexpected Bracket?

Posted: Fri Dec 12, 2008 4:16 am
by papa
foreach (array_expression as $value)