0
votes

My english is not good so sorry for any mistake.I was trying to use codeigniter pagination library , but i am facing a problem it create extra links. My data completes in two pages but there are 4 page links appearing in the bottom when i click on 3rd or 4th link it give error. Here is my Controller code..

 public function usr_list(){
    $config = array();
    $config["base_url"] = base_url() . "usr/usr_list";
    $config["total_rows"] = $this->ListModel->record_count();
    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['first_link'] = false;
    $config['last_link'] = false;
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['prev_link'] = '&laquo';
    $config['prev_tag_open'] = '<li class="prev">';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '&raquo';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config["per_page"] = 10;
    $config["uri_segment"] = 3;
    $choice = $config["total_rows"] / $config["per_page"];
    $config["num_links"] = round($choice);

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    $data["results"] = $this->ListModel->getUser($config["per_page"] , $page);
    $data["links"] = $this->pagination->create_links();
    $this->load->view('userList' , $data);
}

That's my Model code

function getUser($limit , $start){

    $this->db->select("u_id,name,email,phone,cnic");
    $this->db->from('user');
    $this->db->limit($limit , $start);
    $query = $this->db->get();
    if($query->num_rows() > 0) {
    foreach ($query->result() as $rows) {
    $data[] = $rows;
  }
  return $data;
}
return false;

}

In the picture you can see last record is on page 2 but there are 4 links

Any suggestion?

1
Can you post your "record_count" function in the "ListModel" model?Vivek
Change $config["num_links"] = 1; or even 0 as this is the number of pages to show before and after the current page. The actual links are calculated on the total_rows and per_page settings.TimBrownlaw
@vivek this is the code of round function: public function record_count() { return $this->db->count_all($this->db->dbprefix . 'attendence'); }sameed ul hassan
@TimBrownlaw by doing this problem is not solving because after 2nd page when i click on next page it still show the same error.sameed ul hassan

1 Answers

2
votes

Your record_count() function is returning the number of entries in the 'attendence' table, while the data displayed in the paginated table is from the 'user' table (getUser function). The 'attendence' table probably will be having more records than in the 'user' table which is giving you the extra pagination links.

Change your record_count() function as follows.

public function record_count() {
  return $this->db->count_all('user');
}