codeigniter 分页页码问题
codeigniter pagination page number issue
我正在尝试使用 Codeigniter 分页库,我希望我的分页 url 是这样的:
我的网站。com/codeigniter/controller/page/1
我的网站。com/codeigniter/controller/page/2
我的网站。com/codeigniter/controller/page/3
这是我的控制器:
class Controller extends CI_Controller {
public function index() {
$this->load->model('model');
$segment=$this->uri->segment(3);
/* Pagination */
$config['base_url']=base_url('controller/index');
$config['total_rows']=$this->model->count_active_members()->num_rows;
$config['per_page']=5;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
/* END Pagination */
$result['members']=$this->model->get_active_members($segment);
$this->load->view('view',$result);
}
}
我的模型:
class Model extends CI_Model {
public function get_active_members($segment) {
$this->db->select('username,email,balance,ctimes,regdate');
$this->db->limit(5,$segment);
return $this->db->get_where('members',array('status'=>'active'));
}
public function count_active_members() {
return $this->db->get_where('members',array('status'=>'active'));
}
}
它如我所愿地工作,但问题是我的数据库中有 9 行并且它只显示 7
我认为你的问题是偏移量,试试这个:
$this->db->select('username,email,balance,ctimes,regdate');
$per_page = 5;
$segment = $segment > 0 ? (($segment - 1) * $per_page) : $segment;
$this->db->limit($per_page, $segment);
我正在尝试使用 Codeigniter 分页库,我希望我的分页 url 是这样的:
我的网站。com/codeigniter/controller/page/1
我的网站。com/codeigniter/controller/page/2
我的网站。com/codeigniter/controller/page/3
这是我的控制器:
class Controller extends CI_Controller {
public function index() {
$this->load->model('model');
$segment=$this->uri->segment(3);
/* Pagination */
$config['base_url']=base_url('controller/index');
$config['total_rows']=$this->model->count_active_members()->num_rows;
$config['per_page']=5;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
/* END Pagination */
$result['members']=$this->model->get_active_members($segment);
$this->load->view('view',$result);
}
}
我的模型:
class Model extends CI_Model {
public function get_active_members($segment) {
$this->db->select('username,email,balance,ctimes,regdate');
$this->db->limit(5,$segment);
return $this->db->get_where('members',array('status'=>'active'));
}
public function count_active_members() {
return $this->db->get_where('members',array('status'=>'active'));
}
}
它如我所愿地工作,但问题是我的数据库中有 9 行并且它只显示 7
我认为你的问题是偏移量,试试这个:
$this->db->select('username,email,balance,ctimes,regdate');
$per_page = 5;
$segment = $segment > 0 ? (($segment - 1) * $per_page) : $segment;
$this->db->limit($per_page, $segment);