banner image

What is Pagination ?

What is Pagination ?

When you have 1000 of records on your list , its unable to view all data at one time , so we can sort things by means  of pagination. one can define number of records you want to list in page. you can choose 50 records per page or 100 records per page or more than that. according to your choice.

pagination consist of numbers 1, 2, 3,  previous and next button.

Pagination code given below

Controller

$page = $this->uri->segment(4);
if($page == ""){
$page=1;
}

$data["offset"]= $offset=($page_id-1)*10;

$this->load->model('Mstudents','',TRUE);
$total_count=$this->mstudents->get_student_list($count=TRUE, $offset);


$config["base_url"] = base_url()."online_test/student/lis/".$page;
$config["total_rows"] = $total_count;
$config["per_page"] = 10;
$config["use_page_numbers"] = true;

$config["full_tag_open"] = "<ul class='pagination'>";
$config["full_tag_close"] = "</ul>";
$config["first_link"] = "«";
$config["first_tag_open"] = "<li class='footable-page-arrow'>";
$config["first_tag_close"] = "</li>";
$config["last_link"] = "»";
$config["last_tag_open"] = "<li class='footable-page-arrow'>";
$config["last_tag_close"] = "</li>";
$config["next_link"] ="›";
$config["next_tag_open"] = "<li class='footable-page-arrow'>";
$config["next_tag_close"] = "</li>";
$config["prev_link"] = "‹";
$config["prev_tag_open"] = "<li class='footable-page-arrow'>";
$config["prev_tag_close"] = "</li>";
$config["cur_tag_open"] = "<li class='footable-page active'><a href='#'>";
$config["cur_tag_close"] = "</a></li>";
$config["num_tag_open"] = "<li class='page'>";
$config["num_tag_close"] = "</li>";

$this->pagination->initialize($config);
$data["pagination"] = $this->pagination->create_links();


$query =$this->mstudents->get_student_list($count=FALSE, $offset);



Model

function get_student_list($count,$offset)
{

if(!$count){
$this->db->select(*);
}else{
$this->db->select("COUNT(students.student_id) as count");
}

$this->db->from('students');


if(!$count)
$this->db->limit($this->perpagelimit, $offset);

$this->db->order_by('student_id', 'desc');

$query = $this->db->get();

$error_number=$this->db->_error_number();
if($error_number!=0)
{
log_message('error', $this->db->_error_message());
return FALSE;
}

if(!$count)
$result = $query->result_array();
else{
$count = $query->row_array();
$result=$count["count"];
}
return $result;
}


view

<?php echo $this->pagination->create_links(); ?>
What is Pagination ? What is Pagination ? Reviewed by Admin on April 27, 2020 Rating: 5

1 comment:

  1. You've shared some incredibly useful information. This is frequently a terrific way for us to broaden our knowledge while remaining useful. Thank you for bringing this article to our attention. Mexico Import Data

    ReplyDelete

Powered by Blogger.