3
votes

Am getting the error in the code igniter view page as

Invalid argument supplied for foreach() codeigniter in the following code;

<html>
<head>
    <title><?=$page_title?></title>
</head>
<body>
    <?php foreach($result as $row):?>
    <h3><?=$row->title?></h3>
    <p><?=$row->text?></p>
    <br />
    <?php endforeach;?>
</body>

2

2 Answers

7
votes

Test the $result if it is an array, before using foreach on it. Your result may be false since your database query failed, or returned no result.

if (is_array($result))
{
    foreach($result as $row)
    {
        /* ... */
    }
}
1
votes

$result is not an array at all.

You should check the $result construction code. you are not setting $result properly.

If $result is supposed to hold database rows, checkout the database query if that is returning result properly.