How to make pagination query string in codeigniter?

Member

by dedrick , in category: PHP CMS , 8 months ago

How to make pagination query string in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lew , 8 months ago

@dedrick 

To create a pagination query string in CodeIgniter, follow these steps:

  1. Load the pagination library in your controller:
1
$this->load->library('pagination');


  1. Configure the pagination settings by setting the base URL, total rows, and per page limit:
1
2
3
4
5
6
$config = array();
$config["base_url"] = base_url() . "controller/method";
$config["total_rows"] = $total_rows; // Total number of rows to paginate
$config["per_page"] = $per_page; // Number of results per page

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


  1. Generate the pagination links in your view file:
1
echo $this->pagination->create_links();


  1. Handle the pagination query string in your controller method:
1
2
3
$page = ($this->input->get('per_page')) ? $this->input->get('per_page') : 0;

$data['results'] = $this->your_model->get_results($config["per_page"], $page);


Make sure to replace controller, method, your_model, $total_rows, $per_page, and get_results with your actual controller, method, model, total rows count, per page limit, and method to fetch results, respectively.


This will create a pagination query string in CodeIgniter, allowing users to navigate through pages of results.