# CodeIgniter 测试查询结果

**URL:** <https://www.isharkfly.com/t/codeigniter/3579>\
**Category:** PHP\
**Created:** [January 5, 2014, 4:42am UTC](https://www.isharkfly.com/t/codeigniter/3579 "2014-01-05T04:42:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 5, 2014, 4:42am UTC](https://www.isharkfly.com/t/codeigniter/3579/1 "2014-01-05T04:42:46Z")

</div>

如果你的查询可能不返回结果，我们建议你先使用 num\_rows()函数来测试：[code]$query = $this-\>db-\>query(“YOUR QUERY”);

if ($query-\>num\_rows() \> 0)  
{  
foreach ($query-\>result() as $row)  
{  
echo $row-\>title;  
echo $row-\>name;  
echo $row-\>body;  
}  
}[/code]
