查询生成器和条件语句
$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.
我做错了什么?有人可以帮我解决这个问题吗?请!
谢谢你!
$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'];
}
And what the problem is?
Well:
echo $row['thing'] -> nothing.
print_r($query) -> an object and not an array.
What am I doing wrong? Can someone help me on this? Please!
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
try this:
为了扩展上面的答案,问题是执行函数实际上返回 Database_Result。正如上面的文章指出的,您可以在此对象上调用各种函数,然后以各种格式返回数据(请参阅前面的链接以获取可用函数的完整列表)
这提供了各种好处 - 此页面 描述了所有这些
To expand on the above answer, the problem is that the execute function is actually returning an instance of Database_Result. As the above post points out you are able to call various functions on this object that will then return the data in various formats (see the previous link for a full list of available functions)
This provides various benefits - this page describes them all