简体   繁体   中英

How to add pagination codeigniter

How to add pagination codeigniter ?

I tryed to use like this link, but it doesn't work https://www.cloudways.com/blog/pagination-in-codeigniter/

thank you for help me.

Pagination is one of the libraries in the codeigniter...

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

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;

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

echo $this->pagination->create_links();

you can get reference from here... https://www.codeigniter.com/userguide3/libraries/pagination.html

You can also manage pagination manually, it can be easier sometimes depending on what you do: let's say you want batches of 100 results per page, pass a page_number parameter to your controller, then

$results_limit = 100;
$offset = 0;
if (isset($_GET['page_number']))
    $offset = ($_GET['page_number']-1) * $results_limit;
$this->db->select('*');
$this->db->from('sltax_tax_name');
$this->db->order_by("t_id", "desc");
$this->db->limit($offset, $results_limit);
$query = $this->db->get();
// grab your results...

It is easier to use Pagination class from CodeIgniter rather than doing it manually.

https://www.codeigniter.com/userguide3/libraries/pagination.html

In Controller

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

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;

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

In the view

echo $this->pagination->create_links();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM