Reputation: 1270
I'm having some problems with codeigniter and the pagination. The problem is that I get all the results/posts on all pages.
Here is my code:
<?php
class Posts extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('post');
}
function index(){
$data['posts'] = $this->post->get_posts();
$this->load->library('pagination');
$config['base_url']= base_url() .'posts/index/';
$config['total_rows']= $this->post->get_number_of_posts();
$config['per_page']=1;
$this->pagination->initialize($config);
$data['pages']=$this->pagination->create_links();
$this->load->view('index_blog', $data);
}} ?>
What could possible be wrong ?
Thanks in advance.
Upvotes: 1
Views: 1865
Reputation: 1814
Add This to Controller start and limit to your model function argument
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['posts'] = $this->post->get_posts($config["per_page"], $page);
And following to model function get_posts
$this->db->limit($limit, $start);
Upvotes: 2