Controller
//paginationFirst, load the pagination library by writing the code below it will load the functions that are going to be used after.
$this->load->library('pagination');
Configure the base URL that means the controller where you are displaying the data.
$config['base_url'] = "http://localhost/projects/helloworld/loginAdmin/";
Here we get the total number of results.
$total_records = $this->db->count_all('tablename');
$config['total_rows'] = $total_records;
Set the total number of results to show per page. Like here we set to display the 5 items per page on our website.
$config['per_page'] = 5;
Initialize the pagination.
$this->pagination->initialize($config);
Create the segments, segments are the number of pages that are written after the controller/function_name/segment_number understand the thing if now understand still tell us we will clear further in detail.
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
this statement creates the links of base URL and displays the number of results.
$data['pagination'] = $this->pagination->create_links();
then send the data and execute the query.
$data['result'] = $this->crud_model->get_item($config['per_page'] ,$page);
load the view and send the query returned data.
$this->load->view('tableview', $data);
Model
In the model of CodeIgniter mod_pagination.php have the function which will get the database results that we need to show on each page for that we write a query.public function get_item($page, $limit){
$this->db->limit($page, $limit);
$q = $this->db->get('testDb'); return $q->result();
}
View
In CodeIgniter, each and everything is being done like the pattern of MVC, model view and then controller so, here is the view. The page gets the variable from the controller and then we will display that in the pages.<p class="text-center"><?php echo $pagination; ?></p>
This is the simple and easy way to do or implement the pagination in the web application using CodeIgniter. People like to use the framework for their product development because of the fast and easy way to develop then compare to the custom language development. If you have any query in the pagination you can ask here the comment box. For further reading, you can view the CodeIgniter queries that will explain to you how you can write the database queries in an easy way using Codeigniter.
Codeigniter Queries or PHP Queries....!
This Post Was Last Updated On September 30, 2016, By Author: Mahira Khan.
0 comments:
Post a Comment