简体   繁体   中英

pagination not work in CodeIgniter

I want to create pagination using CodeIgniter but I received the following error

Fatal error: Call to a member function query() on a non-object in /home/eheuristic10/php/courtgenie/application/models/kicker_model.php on line 338

and my model are

function ticketCount() {
    $query = $this->db->query("SELECT count(*) as c FROM  ci_ticket_details where userid='" . 2 . "' and activity_status = '0' LIMIT 1");
    $rows = $query->row_array();
    return $rows['c'];
}

and my pagination class is

function attorney_request(){
    $this->load->library('pagination');
    $data['ticketCount'] = $this->kicker_model->ticketCount();
    $config = array();
    $config["base_url"] = 'http://localhost/courtgenie/index.php/kicker/attorney_request';
    $config["total_rows"] = $this->kicker_model->ticketCount();
    $config["per_page"] = 2;
    $config["uri_segment"] = 3;

    $this->pagination->initialize($config);
    $data["activeClient"] = $this->kicker_model->activeTicketsView($config["per_page"], $page);
    $data['pagination'] = $this->pagination->create_links();
    $this->load->view('attorney_request',$data);

    }
    else{
        redirect('home', 'refresh');
    }

}

if I not use pagination class then my pagination will work correct

Thanks

Your SQL is invalid:

$this->db->query("SELECT count(*) as c FROM  ci_ticket_details where userid='" . 2 . "' and activity_status = '0' LIMIT 1");

Your userid cannot be ' . 2 . ' ' . 2 . ' ' . 2 . ' .

Also you are using CI but why aren't you using ACTIVE RECORD for calling such a simple SQL call? Save time use the AR...

http://ellislab.com/codeigniter/user-guide/database/active_record.html

also...
You have poorly formatted indentation for your if statement, and it is broken, have a lonely else and your attorney_request() terminates prematurely.

Try this one into your model

function ticketCount() {
    $this->db->select('count(*) as c');
    $this->db->from('ci_ticket_details');
    $this->db->where('userid', 2);
    $this->db->where('activity_status', 0);
    $this->db->limit(1,0);
    $query = $this->db->get()->row();
    return $query->c;

}

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