Call to a member function num_rows() on a non-object

时光总嘲笑我的痴心妄想 提交于 2019-12-01 10:56:25

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;
}

When you create the $query variable you already added a ->result().

So $query is an array of row objects.

You should change the if to this:

if (count($query) > 0) {

And probably rename the variable to $results for example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!