tags:

views:

43

answers:

2

getting an Warning: Invalid argument supplied for foreach() in /home/maxer/domains/x/public_html/x/items.php on line 41

line 41 is the foreach

$items = getUserList($user,0,100);

foreach($items as $item){

 echo "<img src=\"".$item['image']."\">"; //image
 echo ""; //title
 echo ""; //button for add to list

}
+3  A: 

your function getUserList does not returning array to make sure that $items is array write like this:

$items = (array) getUserList($user,0,100);
Nazariy
bang on- thanks
chris
Make sure you accept his answer if it's right.
BraedenP
After finding solution people forgetting about this website until next issue )
Nazariy
+4  A: 

That means $items is not an array or doesn't implement Traversable. If you supply something that's not an array and doesn't implement Traversable to foreach, it'll complain with this message. Either cast the result of getUserList to an array or check to see if it is one.

$items = (array)getUserList($user,0,100);

or something like this:

$items = getUserList($user,0,100);

if (!is_array($items)) {
    // error
} else {
    foreach ($items …) {
        // …
    }
}
deceze
To be pedantic, any value that's an array *or* implements Traversable can be used in a foreach loop.
Peter Bailey
Alright, alright. ;o)
deceze