1
$query = DB::select('thing')->from('things')->where('thing', '=', 'something');

if ($other_thing)
{
    $query->and_where('other_thing', '=', 'something else');
}

$query->order_by('thing', 'ASC')->limit(10)->execute()->as_array();

foreach ($query as $row)
{
    echo $row['thing'];
}

问题是什么?

好:

echo $row['thing'] -> nothing.
print_r($query) -> an object and not an array.

我究竟做错了什么?有人可以帮我吗?请!

谢谢!

4

2 回答 2

0

试试这个:

$result = $query->order_by('thing', 'ASC')->limit(10)->execute()->as_array();

foreach ($result as $row)
{
    echo $row['thing'];
}
于 2011-05-30T09:42:45.550 回答
0

为了扩展上述答案,问题在于 execute 函数实际上返回了Database_Result的一个实例。正如上面的帖子指出的那样,您可以在此对象上调用各种函数,然后以各种格式返回数据(有关可用函数的完整列表,请参见上一个链接)

这提供了各种好处——这个页面描述了所有这些

于 2011-05-31T09:41:41.650 回答