How to create pagination with letters using codeigniter?

Member

by gilbert , in category: PHP CMS , 20 days ago

How to create pagination with letters using codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 19 days ago

@gilbert 

To create pagination with letters in CodeIgniter, you can follow these steps:

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


  1. Set up the pagination configuration in your controller:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$config['base_url'] = base_url() . 'your_controller/your_method';
$config['total_rows'] = $this->your_model->count_all(); // Get total number of records
$config['per_page'] = 10; // Number of records per page
$config['uri_segment'] = 3;
$config['use_page_numbers'] = FALSE;
$config['display_pages'] = FALSE;
$config['num_links'] = 3;
$config['use_global_url_suffix'] = FALSE;

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


  1. Modify your model to fetch records based on the limit and offset provided by the pagination:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public function get_records($limit, $offset) {
    $this->db->limit($limit, $offset);
    // Add your query to fetch records here
    $query = $this->db->get('your_table');
    return $query->result();
}

public function count_all() {
    return $this->db->count_all('your_table');
}


  1. In your controller method, fetch the records and load the view with pagination:
1
2
3
4
5
6
7
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$limit = $config['per_page'];
$data['records'] = $this->your_model->get_records($limit, $page);

$data['pagination'] = $this->pagination->create_links();

$this->load->view('your_view', $data);


  1. In your view, display the pagination links with letters:
1
echo $pagination;


This will create pagination with letters in CodeIgniter. Make sure to adjust the configurations and code according to your specific requirements.