简体   繁体   中英

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

i have a problem when i want tou run a function from my controller its said "Call to a member function num_rows() on a non-object".

this is my function named category from my web.php controller

public function categori($id){
    $cek = $this->mymodel->GetKategori("where kode_kategori = '$id'");
    if ($cek->num_rows() > 0) {
        $data = array(
        "produk_populers" => $this->mymodel->GetProduk("where kode_kategori = '$id'")->result_array()
        );

        $comp = array(
            "header" => $this->html_header(),
            "navbar" => $this->html_navbar(),
            "produk_populer" => $this->load->view("produk_populer",$data,true),
            "kategori" => $this->html_kategori(),
            "footer" => $this->html_footer(),
        );
        $this->load->view("index",$comp);

    }else{
        show_404(); 

  }

} 

and this the model

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mymodel extends CI_Model {
public function GetProduk($where=""){
    $data = $this->db->query('select * from produk'.$where);
    return $data;

}

public function GetKategori($where=""){
    $data = $this->db->query('select * from kategori '.$where);
    return $data -> result_array();
}

}

can anyone tell me what's wrong with it? i'm new with this kind of stuff.. thanks

It means the returned value from:

$cek = $this->mymodel->GetKategori("where kode_kategori = '$id'");

is not an object. So the method num_rows() does not exist in that value context.

Try using var_dump($cek) right before you call this method and see what the output is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM