为foreach()codeigniter提供的参数无效

jen*_*eni 3 php codeigniter

我在代码点火器视图页面中收到错误

在以下代码中为foreach()codeigniter提供的参数无效;

<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>
Run Code Online (Sandbox Code Playgroud)

aor*_*sik 7

$result在使用foreach之前测试它是否是数组.您的结果可能是false因为您的数据库查询失败,或者没有返回结果.

if (is_array($result))
{
    foreach($result as $row)
    {
        /* ... */
    }
}
Run Code Online (Sandbox Code Playgroud)