Welcome Guest, Not a member yet? Register   Sign In
Can't get pagination working
#4

(12-20-2015, 05:26 PM)skunkbad Wrote: First thing I see is that you are trying to implement paging on the index method of a controller, and this doesn't seem possible. Try changing to a different name for your method.

Next, in order to get pagination working easily, use a page parameter for the method, like this:


PHP Code:
public function something$page ){
   // ....



So you are now able to set the pagination base URL to "page/something", and your $page variable is easily used.

If you feel you must use the index method, you'll want to look at the "remapping" feature in the docs.


Here is code that is working in 3.01 for me

PHP Code:
if ($this->input->post('dept_id') != "") {
        
$dept_id $this->input->post('dept_id');
} else {
        
$dept_id $this->uri->segment(3,0);
}
$this->load->model('Db_model');
$page_cnt 20;
// Creating the pagination menu on the webpage
$this->load->library('pagination');
$config['base_url'] = base_url("employee_list/display_result/$dept_id");
$config['total_rows'] = $this->Db_model->total_rows('employees''department_id'$dept_id);
$config['per_page'] = $page_cnt;
$config['attributes'] = array('class' => 'btn btn-default btn-lg active');
$config['cur_tag_open'] = "<b class='btn btn-primary btn-lg active'>";
$config['cur_tag_close'] = '</b>';
$this->pagination->initialize($config);
$data['paginate'] = $this->pagination->create_links(); 

This is the SQL function I created for getting total rows
PHP Code:
function total_rows($table =""$field ""$id "") {
    
$result "";
    if (
$field != "" && $id != "") {
        
$this->db->where($field$id);
        
$this->db->from($table);
        
$result $this->db->count_all_results();
    } 
            
    if (
$result != "") {
        return 
$result;
    } else {
        return array(
'error'=>'No result found');
    }

Reply


Messages In This Thread
Can't get pagination working - by ditolakgebetan - 12-18-2015, 04:19 AM
RE: Can't get pagination working - by rymesaint - 12-20-2015, 04:50 PM
RE: Can't get pagination working - by skunkbad - 12-20-2015, 05:26 PM
RE: Can't get pagination working - by mike7418 - 12-27-2015, 04:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB