Welcome Guest, Not a member yet? Register   Sign In
Pagination Probelm
#1

[eluser]Unknown[/eluser]
Hi, I am getting some problem with the pagination,
I am trying to display 5 items but all the items in the database is showing up. Below is the code I am using.

$config['base_url'] = "http://localhost/zb/index.php/category/post/$cat";
$config['total_rows'] = $this->db->get_where('posts', array('category' => $cat))->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 10;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';

$this->pagination->initialize($config);
$query=$this->db->get_where('posts', array('category'=>$cat));

if($query->num_rows() > 0)
{
foreach ($query->result() as $rows)
{
$data[] = $rows;
}
return $data;
}
#2

[eluser]Atharva[/eluser]
You are selecting all records from database, so naturally it will show all records! You need to limit the records your query returns using sql LIMIT.
Code:
$query = "select * from table LIMIT $offset, $perpage";

where $offset = $this->uri->segment(4,0);
and $perpage = 5 ;// number of records you want to show

you are also missing $config['uri_segment'] = 4;




Theme © iAndrew 2016 - Forum software by © MyBB