php - Foreach in CodeIgniter -


I want to leave some news first and I have got an error supply for foreach invalid argument: Model:

  public function get_all_news_home () {$ excluded = array (); $ This- & gt; Load-> Database (); $ Last_news_query = $ this- & gt; Db- & gt; Query (Select "News type = 1 from * and ready = 'Y' order date 4" from DESC limit); $ Last_news = $ this- & gt; Db- & gt; Query ($ last_news_query); $ Last_news = ($ last_news- & gt; num_rows ())? $ Last_news- & gt; Result_are (): null; Forex Currency ($ last_news as $ ln) {array_push ($ Excluded, array ('id' = & gt; $ ln ['id'])); } $ NewsIds = implode (',', array_values ​​($ Excluded)); $ All_news = $ this- & gt; Db- & gt; Query (News from "Select * where news.rd = 'wi' and news. Not in IIT ('$ news eds' order order dsc limit 12"); If ($ all_news- & gt; num_rows ()) {$ all_news = $ all_news- & gt; Result_are (); } And {$ all_news = NULL; } Return $ All_news; }   

Controller: $ this-> Data ["all_news"] = & amp; This- & gt; Site_news- & gt; get_all_news_home ();

Change it. You should check the tap status before forwarding.

  public function get_all_news_home () {$ exclude = array (); $ This- & gt; Load-> Database (); $ Last_news_query = $ this- & gt; Db- & gt; Query ("news from selection where type = 1 and ready = 'wi' order date dsc limit 4 '); $ last_news = $ this-> db- & gt; query ($ last_news_query); $ Last_news = ($ Last_news-> num_rows ())? $ Last_news- & gt; result_are (): naval; $ all_news = NULL; if ($ last_news! = NULL) {foreach ($ last_news as $ ln) {array_push ($ Excluded, array ('id' = & gt; $ ln ['id']))} $ NewsIds = implode (',', array_values ​​($ Excluded)); $ All_news = $ this- & gt; db -> News (News) where news.rd = 'wi' and news. Not in IIT ('$ News IDs') order dated ESC limit 12 "); if ($ all_news-> num_rows ()) {$ all_news = $ all_news-> result_re ();}} return $ all_news;}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -