John Davidson

php - Codeigniter pagination list all records from database table instead of list limit

0 comments
Message:


I have used below code for codeigniter pagination.But it list all reocrds from the database table .Pagination not working


$SQL = "SELECT * FROM list AS a ".$search_condition."  "; 
$query = $this->db->query($SQL);
$finaldata=array();
$finaldata['num_results']= $query->num_rows();
//how many blogs will be shown in a page
$limit = $finaldata['num_results'];
$start_limit = ($offset-1) * $limit;

echo $SQL = "SELECT * FROM list AS a ".$search_condition." LIMIT ".$start_limit.",".$limit." ";
$query = $this->db->query($SQL);

if($query->num_rows() > 0)
{
$finaldata['data']= $query->result_array();
}

// load pagination library
$this->load->library('pagination');
$config = array();
$config['base_url'] = site_url("adminuser/list");
$config['total_rows'] = $finaldata['num_results'];
$config['per_page'] = $limit;
//which uri segment indicates pagination number
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
//max links on a page will be shown
$config['num_links'] = 5;
//various pagination configuration
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
<! some code here ->
$config['cur_tag_close'] = '</span>';
$this->pagination->initialize($config);
$finaldata['pagination'] = $this->pagination->create_links();
$this->load->view('admin/list',$finaldata);

I try to list 10 records per page in the list page . but it is not working



My Answer:
"SELECT * FROM table_name";
$query = $this->db->query($SQL);

$config['base_url'] = base_url('controller_name/method_name');
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 10;

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

$data['records'] = $query->result();

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

In the above code, make sure you have loaded the pagination library in your controller. Also, ensure that you have set the base_url correctly and that the total_rows and per_page values are set appropriately. If the pagination is still not working, check if the pagination links are being displayed in your view and if the URL parameters are being passed correctly.

Rate this post

4 of 5 based on 5206 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us