xwzscE
xwzscE

Reputation: 20

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.

Upvotes: 0

Views: 156

Answers (3)

Pavan Nagadiya
Pavan Nagadiya

Reputation: 682

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

Upvotes: 3

Nish
Nish

Reputation: 1137

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();

Upvotes: 0

JBA
JBA

Reputation: 2899

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...

Upvotes: 0

Related Questions