Welcome Guest, Not a member yet? Register   Sign In
Pagination problem
#1

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');
    } 
Reply
#2

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

didn't get your question, sorry. I am following a video tutorial http://code.tutsplus.com/tutorials/codei...--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>
Reply
#4

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.
Reply
#5

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

Smile

thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB