Weird Error

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 22, 2015   (RSS)

By Dave - June 22, 2015

Hi Ragi, 

This error: "E_WARNING: Invalid argument supplied for foreach() ..." usually means the $records array is empty.  You can either wrap for foreach in an if block like this:

if ($records) { 
  foreach ($records as $record) { 
    ...
  }
}

Or you could try forcing $records to be an array by adding (array) in front to force (type cast) it into an array.  Test and make sure that works before sticking with it:

foreach ((array) $records as $record) { 
  ...
}

Or just exit at the top of the page or display an error if no records are found.

And for the URL in the error log entry... The error log functions try to guess the current url.  It could be wrong, or the one file could be including the other, or something else interesting.  The url does start with /minutes_e.php/ ... You could try this url and see if it works: http://insert_your_domain/minutes_e.php/photo/photo/activities_e.php?Marksmanship-6  In any case, those are two unrelated issues.  One is the foreach loop gets called even when the record array is empty, and the other is the either an unexpected URL is being accessed and/or the url is being logged incorrectly.

Hope that helps! Let me know any questions.

Dave Edis - Senior Developer
interactivetools.com

By northernpenguin - June 22, 2015

Thanks Dave

I fixed the first issue as you suggested, so now an empty array will no longer generate a warning.

As for the URL issue, I tried to see what it would generate, and as I suspected it didn't find the file and generated a 404 error.  I will just ignore it and see if it reoccurs.

Ragi

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke