当我在第一页时,我点击分页链接(2),链接(3),链接(4)页面分页链接无效。
<?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);
}
} ?>
答案 0 :(得分:2)
更改此行:
$config["base_url"] = base_url() . "pagination";
到
$config["base_url"] = base_url("pagination/index");
答案 1 :(得分:0)
我想这个方法从数据库中获取数据:
$data["results"] = $this->Countries_Model
->get_countries($config["per_page"], $page);
你还需要传递一个偏移量($ offset是你的情况下的第4段),
控制器中的
public function index($offset = 0) {
.....
$this->Countries_Model
->get_countries($config["per_page"], $page,$offset);
}
在您的模型中
get_countries($per_page, $page,$offset){
......
$this->db->get('yourtable',$per_page, $offset);
}