CodeIgniter Forums
Pagination problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Pagination problem (/showthread.php?tid=1581)



Pagination problem - gabrielpasv - 03-23-2015

Hi Guys,

I am new to codeigniter and I am having a problem when working with pagination.

The $this->pagination->create_links() is always empty it doesn't return anything even if I echo it on controller or in the view

Please see my controller, as this is a test I didn't create a model

PHP Code:
public function index() {
        
$this->load->library('pagination');
        
$config['base_url'] = 'http://192.168.56.101/TUTPagination/site/index';
        
$config['total_rows'] = $this->db->get('data')->num_rows();
        
$config['per_page'] = 10;
        
$config['num_links'] = 20;
        
        
        
$this->pagination->initialize($config);
        
//        echo $config['base_url'];
//        echo $config['total_rows'];
//        echo $config['per_page'];
//        echo $config['num_links'];
        
        
$data['records'] = $this->db->get('data'$config['per_page'], $this->uri->segment(3));
        
$data['links'] = $this->pagination->create_links();
        
        
print_r($data['links']) ;
        
        
$this->load->view('site_view');
    } 



RE: Pagination problem - CroNiX - 03-23-2015

And what uri_segment are you using to display your pagination options?


RE: Pagination problem - gabrielpasv - 03-23-2015

didn't get your question, sorry. I am following a video tutorial http://code.tutsplus.com/tutorials/codeigniter-from-scratch-day-7-pagination--net-7023

I forgot to pass $data to the view. However still not working

my controller
public function index() {
$this->load->library('pagination');
$config['base_url'] = 'http://192.168.56.101/TUTPagination/site/index';
$config['total_rows'] = $this->db->get('data')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 20;

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


$data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
$data['links'] = $this->pagination->create_links();

$this->load->view('site_view', $data);
}

}



my view

<div id="container">
<h1>Super Pagination with codeIgniter</h1>
<?php echo $this->pagination->create_links(); ?>
<?php echo $links; ?>
</div>


RE: Pagination problem - CroNiX - 03-23-2015

See the options for the pagination library. By default, CI looks at segment 3 to determine what page it's currently on, but it looks like you are using segment 4 since your base_url is http://192.168.56.101/TUTPagination/site/index (segment 1=TUTPagination, 2=site, 3=index, 4=should be page number). So right now it thinks the page number is "index" and probably not being able to load the content for that "page" since it doesn't exist.


RE: Pagination problem - gabrielpasv - 03-23-2015

I was able to make it work.. the problems was number of rows in my database

Smile

thanks