CodeIgniter问题从DB检索和显示数据 [英] CodeIgniter problem retrieving and displaying data from DB
本文介绍了CodeIgniter问题从DB检索和显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是我的功能。这很简单。
Here is my function. It is very simple.
function load_data() {
$query = $this->db->query('SELECT * FROM configurations WHERE username="' . $this->session->userdata('username') . '"');
return $query;
}
我的控制器有这行代码:
My controller has this line of code:
$data['query'] = $this->configurations->load_data();
在我看来,我试过:
foreach($query->result_array() as $row) {
echo $row->first;
}
但我收到一个错误,非对象的属性。
But I get an error that I am trying to get a property of a non-object. Isn't the query being returned from the model as an object?
推荐答案
你应该使用$ query-> result_array,row_array,结果或行,否则返回对象intead得到结果。检查CI手册。
You should use $query->result_array, row_array, result, or row otherwise your returning the object intead get the results. Check the CI manual.
这篇关于CodeIgniter问题从DB检索和显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文