[eluser]maria clara[/eluser]
hi to all,
i am also new in CI. i also encountered that pagination problem. try this in your model. these scripts i used for my pagination and it works. hope you can get an idea with this.
Code:
$page = $this->input->post('page');
$limit = $this->input->post('rows'); // get how many rows we want to have into the grid
$sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
$sord = $this->input->post('sord'); // get the direction
if (!$sidx) $sidx = 'role_id'; //the primary key
if (!$sord) $sord = 'asc';
if (!$page) $page = 1;
if (!$limit) $limit = 25;
$start = (($page-1) * $limit);
$this->db->start_cache();
/* some code here for your database query*/
$this->db->order_by($sidx,$sord);
$this->db->limit($limit, $start);
$query = $this->db->get("ar_sales"); //the table name you are using
$count = $this->db->count_all_results();
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit * $page - $limit; // do not put $limit*($page - 1)
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
$this->db->flush_cache();
$data['db'] = $query;
$data['page'] = $page;
$data['totalpages'] = $total_pages;
$data['totalrecords']=$count;
return $data;
hope this could help you.
regards,
maria