Jump to content

Warning: Invalid argument supplied for foreach()


Sh4dowDan

Recommended Posts

I get this error:

Warning: Invalid argument supplied for foreach() in E:\xampp\htdocs\pages\file.php on line 269

269 line:

foreach ($announcements as $announcementsRow){

 

What is wrong with my .php file? could you please correct it?

///show news$announcements = $SQL->query("SELECT * FROM `announcements` WHERE id ORDER BY `date` DESC LIMIT 1");foreach ($announcements as $announcementsRow){$news_content .= '<div id="featuredarticle" class="Box"><div class="Corner-tl" style="background-image:url('.$layout_name.'/images/content/corner-tl.gif);"></div><div class="Corner-tr" style="background-image:url('.$layout_name.'/images/content/corner-tr.gif);"></div><div class="Border_1" style="background-image:url('.$layout_name.'/images/content/border-1.gif);"></div><div class="BorderTitleText" style="background-image:url('.$layout_name.'/images/content/title-background-green.gif);"></div><img class="Title" src="montaimg.php?text=Announcement" alt="Contentbox headline" /><div class="Border_2"><div class="Border_3"><div class="BoxContent" style="background-image:url('.$layout_name.'/images/content/scroll.gif);"><div id="TeaserThumbnail"><img src="images/news/announcement.jpg" width="150" height="100" border="0" alt="" /></div><div id="TeaserText"><div style="position: relative; margin-bottom: 2px;" ><div style="font-size:18px; font-weight:bold;">'.$announcementsRow['title'].'</div></div>'.$announcementsRow['text'].'<br /><br /><small style="float: right;">Posted by <font color="red">'.$announcementsRow['author'].'</font> - '.date("d M Y", $announcementsRow['date']).'</small>';if ($logged)if ($account_logged->getCustomField("page_access") > 6 ){ $news_content .='<input type="button" value="Deletar" OnClick="location.href=\'index.php?subtopic=cpanel&action=deletar_ann&id='.$announcementsRow['id'].'\'" />';} $news_content .='</div></div></div></div> <div class="Border_1" style="background-image:url('.$layout_name.'/images/content/border-1.gif);"></div><div class="CornerWrapper-b"><div class="Corner-bl" style="background-image:url('.$layout_name.'/images/content/corner-bl.gif);"></div></div><div class="CornerWrapper-b"><div class="Corner-br" style="background-image:url('.$layout_name.'/images/content/corner-br.gif);"></div></div></div>';} //

Link to comment
Share on other sites

Where id is true (ie non=zero)

 

example

mysql> SELECT
    ->   id
    -> , username
    -> FROM users
    -> WHERE id
    -> ORDER BY status;
+----+----------+
| id | username |
+----+----------+
|  2 | User 222 |
|  4 | User 444 |
|  1 | User 111 |
|  3 | User 333 |
+----+----------+
4 rows in set (0.00 sec)
Link to comment
Share on other sites

Have you tried firing up MySQL workbench and typing your query in there to see if it runs okay ?  (that's often a starting point for me when debugging). Otherwise, just double check that your variable $SQL is actually what it needs to be.

Edited by grissom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.