Sh4dowDan Posted June 1, 2015 Share Posted June 1, 2015 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>';} // Quote Link to comment Share on other sites More sharing options...
blacknight Posted June 1, 2015 Share Posted June 1, 2015 i would make sure $SQL->query is returning a array which its probably not you can use print_r($announcements); to see if it is .. i think you will find that its returning a resources not an array Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted June 1, 2015 Share Posted June 1, 2015 Your SQL is incomplete ...WHERE id ORDER BY... Where id what? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 1, 2015 Share Posted June 1, 2015 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) Quote Link to comment Share on other sites More sharing options...
grissom Posted June 1, 2015 Share Posted June 1, 2015 (edited) 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 June 1, 2015 by grissom Quote Link to comment Share on other sites More sharing options...
Barand Posted June 1, 2015 Share Posted June 1, 2015 Having executed the query you have to fetch the results before you can loop through them. Quote Link to comment Share on other sites More sharing options...
Sh4dowDan Posted June 1, 2015 Author Share Posted June 1, 2015 Just deleted this not completed code. Problem solved : p That was an additional stuff that i didnt need. I had no table announcements etc so i couldnt add it anyways. Thanks for reply, have a nice day. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.