Unexpected Bracket?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
millsy007
Forum Commoner
Posts: 78
Joined: Wed Jul 02, 2008 7:00 pm

Unexpected Bracket?

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Unexpected Bracket?

Post by jaoudestudios »

Your foreach is wrong. That is not how you do a foreach, I think you want to do a while instead.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Unexpected Bracket?

Post by papa »

foreach (array_expression as $value)
Post Reply