开发者

Invalid argument supplied for foreach! [duplicate]

This question already has answers here: Closed 9 years ago.

Possible Duplicate:

Invalid argument supplied for foreach()

I have the following code:

<?
foreach($format as $form)
{
    echo $form;
    ?>
    <ul>
        <?
        $s = $database->onlineFormatUsers($form);
        while($row=mysql_fetch_assoc($s))
        {
            $username=$row['username'];
            $id=$row['id'];?>
            <li><a href="../userprofile.php?id=<?echo $id?>"><?echo "$username";?></a&g开发者_JAVA百科t;</li>
        <?
        }
        ?>
    </ul>
    <?
}
?>

<? 
//the active formats
$f = $database->activeFormats();
while($row=mysql_fetch_assoc($f))
{
    $format=$row['name'];
}
?>

It is saying its an invalid argument? Any reason why? Thanks


$format is probably not an array.

Wrap the foreach block in an if(is_array($format)) { } block or cast it to an array by doing $format = (array)$format.


are you sure $format is an array ? put an

<?php echo gettype($format); ?>

before the foreach loop


$format is not array or not exists! Before foreach

if(is_array($format)){  
   foreach($format ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜