简体   繁体   中英

Codeigniter : Fatal error: Call to a member function num_rows() on a non-object

I have problem in link of my script by Codeigniter. I have this URL :-

localhost/index.php/admin/orders/ Its get me all order of product, But when i add any character in the end of link like this :

localhost/index.php/admin/orders/ggg The user see some error message.

Fatal error: Call to a member function num_rows() on a non-object in 

How can save my link, And hidden this message.

My Controller :-

function orders()
{
    $data['orders'] = $this->admin_model->getOrderList();
    $data['total']  = $this->admin_model->getOrderCount();
    $this->load->view('admin/orders',$data);
}

My Model:-

 function getOrderList()
{
    $page = $this->uri->segment(3);
    if($page=='')
        $page=1;

    $start = ($page-1)*RECORDS_PER_PAGE;
    $end = RECORDS_PER_PAGE;

    $this->db->select("*");
    $this->db->limit($end,$start);

    $this->db->order_by('order_id','DESC');
    $result = $this->db->get('wg_orders');
    if($result->num_rows()>0)
    return $result->result();
    else
    return 'empty';
}

You can use count() function as well.

In Controller

    function orders()
    {
        $data['orders'] = $this->admin_model->getOrderList();
        $data['total']  = $this->admin_model->getOrderCount();
        $this->load->view('admin/orders',$data);
    }

In Model

    function getOrderList()
    {
        $page = $this->uri->segment(3);
        if($page=='')
            $page=1;

        $start = ($page-1)*RECORDS_PER_PAGE;
        $end = RECORDS_PER_PAGE;

        $query = $this->db->query("SELECT * FROM table_name WHERE (your_argument) LIMIT $end, $start ORDER BY order_id DESC ");
        $result = $query->result_array();
        $count = count($result);

        if($count>0)
        {
            return $result;
        }
        else
        {
            return 'empty';
        }
    }

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