在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