Today, We want to share with you pagination in codeigniter.In this post we will show you pagination in codeigniter using ajax, hear for pagination in codeigniter 4 we will give you demo and example for implement.In this post, we will learn about PHP Codeigniter Load Data While Ajax Infinite Scrolling Pagination with an example.
Codeigniter Pagination Class Library
Load migration class library
$this->load->library('pagination');
1. Hiding the pages.
load->library('pagination'); $config['base_url'] = 'http://pakainfo.com/index.php/test/page/'; $config['total_rows'] = 200; $config['per_page'] = 20; $config['display_pages'] = false; $this->pagination->initialize($config); echo $this->pagination->create_links(); } } ?>
2. Adding attribute to anchors.
$config['attributes'] = array('class' => 'myclass');
3. Disabling the “rel” attribute.
$config['attributes']['rel'] = FALSE;
1. Initialize.
initialize([$params = array()])
2. Create links.
create_links()
Full example of pagination.
load->library('pagination'); $config['base_url'] = 'http://pakainfo.com/index.php/test/page/'; $config['total_rows'] = 200; $config['per_page'] = 20; $this->pagination->initialize($config); echo $this->pagination->create_links(); } } ?>
More Example About Pagination
session->flashdata('message'); ?>Pagination Controller Code:-
File Name-[MemberController.php]
load->model('MemberModel'); $this->load->helper('country_helper'); $post_name = $this->input->get('search'); $model = $this->load->model('MemberModel'); $config['base_url'] = base_url().'index.php/memberController/membersdatalist/'; $totalRows = $this->MemberModel->searchMember($post_name); $data['data'] = $this->MemberModel->searchMember($post_name, $start); $config['total_rows'] = count($totalRows); $config['per_page'] = 15; //data per page you want to display. $this->load->library('pagination'); $this->pagination->initialize($config); $this->load->view('common/header_view'); $this->load->view('search_result_view',$data); $this->load->view('common/footer_view'); } } ?>Pagination model Code:-
db->select('*'); $this->db->from(MEMBERS); $this->db->like('name', $post_name); $this->db->or_like('uname', $post_name); $this->db->or_like('email', $post_name); $this->db->limit(10, $start); $query = $this->db->get(); $result = $query->result_array(); return $result; } } ?>I hope you get an idea about dynamic pagination in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.