Reputation: 129
When I'm on the first page I click on pagination link(2),link(3), link(4) page pagination link not working.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pagination extends CI_Controller
{
public function __construct() {
parent:: __construct();
$this->load->helper("url");
$this->load->model("Countries_Model");
$this->load->library("pagination");
}
public function index() {
$config = array();
$config["base_url"] = base_url() . "pagination";
$config["total_rows"] = $this->Countries_Model->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['prev_link'] =TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(2))? $this->uri->segment(2) : 0;
$data["results"] = $this->Countries_Model
->get_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view("pagination", $data);
}
} ?>
Upvotes: 2
Views: 82
Reputation: 298
I suppose that this method fetches the data from your database:
$data["results"] = $this->Countries_Model
->get_countries($config["per_page"], $page);
well you need also to pass an offset (the $offset is the segment 4 in your case),
in your controller
public function index($offset = 0) {
.....
$this->Countries_Model
->get_countries($config["per_page"], $page,$offset);
}
in your model
get_countries($per_page, $page,$offset){
......
$this->db->get('yourtable',$per_page, $offset);
}
Upvotes: 0
Reputation: 8838
change this line :
$config["base_url"] = base_url() . "pagination";
to
$config["base_url"] = base_url("pagination/index");
Upvotes: 2