Codeigniter pagination example

Codeigniter pagination example :

Codeigniter pagination is very easy to use and customize it.

A working example for codeigniter pagination can be as :

Codeigniter pagination example code

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

//this is the path of your current page in which you want to apply pagination
$config['base_url'] = 'http://demo.com/index.php/test/page/';


$config['total_rows'] = 600;//this total count of rows returned from the query
$config['per_page'] = 10; //data per page you want to display.

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

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

Note : You can echo $this->pagination->create_links(); in your view which you are loading in your controller.
Note : By default, It is assumed that you are using URI Segments, and constructs your links something like

http://demo.com/index.php/test/page/20

If you have set

$config['page_query_string'] = TRUE;

Then Your URI Should be like :

http://demo.com/index.php?c=test&m=page&per_page=20

Note : You can use per_page value as your start limit in controller function’s query.


Advertisements

Add Comment

📖 Read More