0

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></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

Community
  • 1
  • 1
sark9012
  • 5,485
  • 18
  • 61
  • 99

3 Answers3

3

$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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

are you sure $format is an array ? put an

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

before the foreach loop

Not Available
  • 3,095
  • 7
  • 27
  • 31
0

$format is not array or not exists! Before foreach

if(is_array($format)){  
   foreach($format ...
}
turbod
  • 1,988
  • 2
  • 17
  • 31