调用一个成员函数NUM_ROWS()在一个非对象 [英] Call to a member function num_rows() on a non-object
本文介绍了调用一个成员函数NUM_ROWS()在一个非对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用codeIgniter,我想在一个数据库从表中的一些数据。
I'm using CodeIgniter, and I want to get some data from a table in a database.
在我的模型,我有这样的功能:
in my Model, I have this function :
public function fetch_cours($limit, $start, $element) {
$id_element = $this->db->from('element')
->where('name',$element)
->limit(1)
->get()
->result();
$query = $this->db->from('cour')
->where('id_element',(int) $id_element[0]->id)
->limit($limit, $start)
->get()
->result();
var_dump($query);
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
我想这个函数返回一些记录在 COUR
表。
在我的控制器我有这样一行:
In my controller I have this line :
$cours = $this->cours_m->fetch_cours(10,0,'Programmation Orientée Objet (Java)');
当我把我的控制器我得到这个消息:
When I call my controller I get this message :
行38:如果($查询 - > NUM_ROWS()0){
所以,我做了一个后续代码var_dump($查询),这是输出:
So I did a var_dump($query) and this is the output :
这是什么问题?我怎么能解决呢?
What's the problem ? and how can I solve it ?
推荐答案
电话 - >结果(),你有一个数组的查询执行的结果。你可以打电话给你的变量是这样,例如:
Calling ->result(), you have the result of the query execution in an array. You might call your variable like this, for example :
$cours = $this->db->from('cour')
->where('id_element',(int) $id_element[0]->id)
->limit($limit, $start)
->get()
->result();
然后改变你的测试为:
Then change your test as :
if (count($cours) > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
这篇关于调用一个成员函数NUM_ROWS()在一个非对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文