我的分頁限制是 5,每頁有 5 個帖子?,F(xiàn)在在第 1 頁上我有 5 個帖子,但是當我轉(zhuǎn)到第 2 頁時,它會在第一頁之后跳過 5 個帖子,并從帖子 #11 開始第二頁,從第 2 頁到結束,所有帖子都正確顯示。然后最后一頁是空的。(這意味著跳過了第 6 到 10 個帖子)我嘗試更改限制 $this->global_limit = 5; 到任何其他號碼。問題仍然存在,例如如果我將限制更改為 10 個第一頁將顯示 10 個帖子,然后跳過第 11 到 20 個帖子并從第 21 頁開始第 2 頁。 /** * Code in controller file */ $this->global_limit = 5; $this->params['lang_id'] = $this->lang_id; $this->params['limit'] = $this->global_limit; $this->params['slug'] = $this->slug; /** * Code in Helper file */function get_blog_posts($params, $category_rewrite){ $CI = &get_instance(); /** * Count and get all the posts */ $posts_count = $CI->blog->getPosts($params, TRUE); $posts = $CI->blog->getPosts($params); /** * Pagination */ $config['base_url'] = $category_rewrite['slug'] . 'page/'; $config['total_rows'] = (int)$posts_count; $config['per_page'] = isset($params['limit']) ? (int)$params['limit'] : FALSE; $config['uri_segment'] = 5; $config['num_links'] = 10; $config['use_page_numbers'] = TRUE; $config['suffix'] = $CI->uri->getpath() ? '/?' . $CI->uri->getpath() : ''; $config['first_url'] = $category_rewrite['slug']; $CI->pagination->initialize($config); $pagination = $CI->pagination->create_links(); /** * Code in model file */ public function getPosts($params, $count = FALSE){ $params = array_merge($this->params, $params); extract($params); $this->db->join('blog_posts_langs as bpl', 'bp.id = bpl.post_id', 'left'); $this->db->join('blog_categories as bc', 'bc.id = bp.category_id', 'left'); $this->db->join('blog_categories_multi as bcm', 'bcm.post_id = bp.id', 'left'); $this->db->join('url_rewrite as urwr', 'urwr.url_type = "blog_post" AND urwr.element_id = bp.id AND urwr.lang_id = '. $lang_id, 'left'); if ($category) { $this->db->where('(bc.id = "' . $category . '" OR bc.parent_id IN (' . $in_categories . ') OR bcm.category_id = '. $category .' )'); }
2 回答

收到一只叮咚
TA貢獻1821條經(jīng)驗 獲得超5個贊
在模型文件中編輯對我有用。下面是我的代碼片段。非常感謝@balakrishnan
$page = $this->uri->segment(5,1);
if ($limit) {
$this->db->limit($limit,($page-1) * $limit);
}

偶然的你
TA貢獻1841條經(jīng)驗 獲得超3個贊
對于分頁,
第 1 頁:0 - 4(索引從 0 開始)
第 2 頁:5 - 9
您需要按如下方式計算起始值
$start = ($page-1) * $limit;
然后它會正常工作。
您需要在控制器文件中添加此代碼
$this->params['limit'] = $this->global_limit;
$start = $this->uri->segment(4);
$this->params['start'] = $start
您可能需要檢查獲取頁碼或起始偏移量的段值。如果您獲得頁碼,則需要應用上述計算以從頁碼獲取起始偏移量。此外,段號可以根據(jù)您的 url 參數(shù)而變化。
- 2 回答
- 0 關注
- 169 瀏覽
添加回答
舉報
0/150
提交
取消