在codeigniter分页类中使用_page_numbers? [英] use_page_numbers in codeigniter pagination class?
问题描述
我在我的分页类中使用 use_page_numbers 配置设置为 true 时遇到问题!当我点击第 2 页的链接时,它从数据库中检索的行数是正确的,但问题是:第二页的第一行是第一页的第三行!这意味着第 2 页从数据库中的同一行开始,该行已在第三行的第一页中检索到.例如:
I have a problem with using use_page_numbers config set to true in my pagination class! When I click on the link of page 2, the number of rows it retrieves from database is correct, but the problem is that: the first row of page 2 is the third row of page one ! It means that page 2 starts with the same row from the database which has been retrieved in the first page in the third row. for example :
第 1 页:10、11、12、13、14
Page 1: 10, 11, 12, 13, 14
第 2 页:12、13、14、15、16
Page 2: 12, 13, 14, 15, 16
当然第 3 页从第 2 页的第二行开始:
and of course the page 3 starts from the second row of page 2 :
第 3 页:13、14、15、16、17
Page 3: 13, 14, 15, 16, 17
这是我的代码:
function get_brands_list($options = array())
{
//Pagination config
$config['base_url'] = base_url() . 'admin/brands/page/';
$config['total_rows'] = $this->db->get('mg_brands')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 4;
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$offset = $this->uri->segment(4, 0);
$this->db->order_by('brand_Sort', 'ASC');
$query = $this->db->get('mg_brands', $config['per_page'], $offset);
if(isset($options['brand_Id']) || isset($options['brand_Name']))
return $query->row(0);
return $query->result();
}
推荐答案
您在计算偏移变量时遇到问题....试试这个:
You have a problem in calculation of offset variable.... Try this one:
$page_num = $this->uri->segment(4, 0);
$offset = ($page_num - 1) * $config['per_page'];
这篇关于在codeigniter分页类中使用_page_numbers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!