Pagination Probelm - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Pagination Probelm (/showthread.php?tid=41134) |
Pagination Probelm - El Forum - 04-28-2011 [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; } Pagination Probelm - El Forum - 04-29-2011 [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"; |