在CI的分页,数据指标应遵循的偏移。例如:如果限制为10,则第二个指标应该有10抵消,这意味着该指数将开始从11至20CodeIgniter的分页偏移不工作
我跟着一些教程,但我仍然无法得到这个偏移事情正常工作。 我每次点击不同的分页索引时,我的索引总是被重设为1。
这是我的分页代码,音符,我试图呼应$offset
,值为真(在第二索引= 10,在第三索引= 20,用$limit
= 10)所以我不知道为什么它不工作:
public function index($offset = 0) {
//check authorization
if(!isset($_SESSION['username']))
redirect('backend_umat/login');
// the $offset value is true, but the index is still reseted to 1
echo $offset;
$limit = 10;
$result = $this->umat_m->get_umat($limit, $offset);
//pagination
$config['base_url'] = site_url('/backend_umat/index');
$config['total_rows'] = $result['num_rows'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
这是我的模型:
public function get_umat($limit, $offset) {
$this->db->select('*')->from('msumat')->limit($limit, $offset)->
join('mskelas', 'msumat.kelas_id = mskelas.kelas_id');
$q = $this->db->get();
$result['rows'] = $q->result();
$result['num_rows'] = $this->db->select('*')->from('msumat')->
join('mskelas', 'msumat.kelas_id = mskelas.kelas_id')
->get()->num_rows();
return $result;
感谢˚F或你的帮助:D
我不能在代码中查看错误,如果偏移量正确,那么您的查询又如何? 'echo $ this-> db-> last_query()'在你的模型中的第一个查询之后。什么是错误的,从数据库或分页html数据? – Aurel 2013-05-05 13:51:51