CodeIgniter Forums
undefined table data, pagination related - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: undefined table data, pagination related (/showthread.php?tid=52077)



undefined table data, pagination related - El Forum - 05-29-2012

[eluser]zgames[/eluser]
I'm trying to get users only with gender M, however pagination is trying to get all the values, therefore when the value is not equal it gives me this error, other wise everything is working perfectly fine


could someone give me advice how to solve this problem?


my model
Code:
function list_all(){
  $this->db->order_by('id','asc');
  return $this->db->get($tbl_person);
}

function count_all(){
  return $this->db->count_all($this->tbl_person);
}

function get_paged_list($gender,$limit = 10, $offset = 0){
  $this->db->order_by('id','asc');
  return $this->db->get_where($this->tbl_person,array("gender" => $gender), $limit, $offset);
}

my controller
Code:
$puslapiai = $this->Puslapiai_model->get_paged_list('M', $this->limit, $offset)->result();
  
  // generate pagination
  $this->load->library('pagination');
  $config['base_url'] = site_url('puslapiai/index/');
   $config['total_rows'] = $this->Puslapiai_model->count_all();
   $config['per_page'] = $this->limit;
  $config['uri_segment'] = $uri_segment;
  $this->pagination->initialize($config);
  $data['pagination'] = $this->pagination->create_links();
  
  // generate table data
  $this->load->library('table');



undefined table data, pagination related - El Forum - 05-29-2012

[eluser]zgames[/eluser]
bump



undefined table data, pagination related - El Forum - 05-29-2012

[eluser]CroNiX[/eluser]
If you are using a where in your query to get the results, you need to use the same where when you are getting the count.

lets say you had 50 males and 50 females.
If you query to get males, you get 50, but your count function is still returning 100 because you don't have the same where (only males) in it.


undefined table data, pagination related - El Forum - 05-29-2012

[eluser]zgames[/eluser]
Code:
function count_all($gender){
     $this->db->count_all($this->edit_pages);
     $query = $this->db->get_where($this->edit_pages, array("gender" => $gender));
     return  $count = $query->num_rows();
}
seems to work

thanks for solution