Welcome Guest, Not a member yet? Register   Sign In
Invalid argument supplied for foreach()
#2

[eluser]davidbehler[/eluser]
Quote:If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned.
from http://php.net/manual/en/function.count.php

That being said, your error is quite easy to fix.
Your model returns either an array or FALSE. count() will return the number of elements in your array or 1 if the returned values from your model is FALSE.

Instead of
Code:
if($total > 0){
}
I would use
Code:
if(is_array($query) {
}
or
Code:
if($total > 0 AND $query !== FALSE){
}

Hope that helps.


Messages In This Thread
Invalid argument supplied for foreach() - by El Forum - 07-20-2010, 08:59 PM
Invalid argument supplied for foreach() - by El Forum - 07-21-2010, 02:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB