Php 为foreach()codeigniter提供的参数无效
我在CodeIgniter视图页面中得到错误,如下所示 以下代码中为foreach()codeigniter提供的参数无效Php 为foreach()codeigniter提供的参数无效,php,codeigniter,Php,Codeigniter,我在CodeIgniter视图页面中得到错误,如下所示 以下代码中为foreach()codeigniter提供的参数无效 <html> <head> <title><?=$page_title?></title> </head> <body> <?php foreach($result as $row):?> <h3><?=$row->title?&g
<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>
$result
根本不是数组
您应该检查$result
构造代码。您没有正确设置$result
如果
$result
应该保存数据库行,请检查数据库查询是否正确返回结果。在对其使用foreach之前,测试$result
是否为数组。由于数据库查询失败,您的结果可能是false
,或者没有返回任何结果
if (is_array($result))
{
foreach($result as $row)
{
/* ... */
}
}
@jeni:“给出代码”正是这个网站的错误态度。这是有利的,如果你做一些思考自己。