0
votes

I am using pagination class in codeigniter for my project and for some reason it's not working correctly. It is only displaying the first 3 results from my db and my "$config[per_page] = 3" and I have 20 items in my database.

Here is my controller:

$this->load->library('pagination');

$config['base_url'] = 'http://localhost/ci/admin/prod/viewprod';
$config['total_rows'] = $this->db->get('retail_prod')->num_rows();
$config['uri_segment'] = 5;
$config['per_page'] = 3;
$config['num_links'] = 5;

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

$data['records'] = $this->db->get('retail_prod', $config['per_page'], $this->uri->segment(5));

Here is my view:

<?php 
echo $this->table->generate($records);
echo $this->pagination->create_links(); 
?>

BTW: I am not using routes yet.

1
Did you check by var_dump() that haopw many data returned from database query?Awlad Liton
yes i did and it returned all the data from my db. I just solved this problem. Instead of using setting $config['uri_segment'] = 5, I just changed it to 4. thanks for your reply anyway.user3119155

1 Answers

0
votes

use this code to show pagination like

$config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '<li>';
        $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '</li>';

        $config['cur_tag_open'] = "<li><span><b>";
        $config['cur_tag_close'] = "</b></span></li>";

Also, in view, use the code as follows:

<div class="pagination">
    <ul>
        {$pagination->create_links()}
    </ul>    
</div>