我在使用codeIgniter分页(修复一个bug)之后得到了一些帮助。我可以在视图中看到记录数和分页链接,但是当点击下一个链接时,它不会显示下一个/前一个10个记录。有人可以帮帮我吗?
我的控制器中有以下代码
function customerlist_pagination()
{
$search = $this->input->post('search');
$data['title'] = "Customer Clist";
$data['heading'] = "List of customers";
$data['result'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "limit_rows");
$data['num_recs'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "num");
$config['base_url'] = base_url().'index.php/customer/customerlist_pagination/';
$config['total_rows'] = $data['num_recs'];
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['next_link'] = 'Next >';
$config['prev_link'] = '< Previous ';
$this->pagination->initialize($config);
$this->load->view('customer_view_table',$data);
}
在模型中,我有以下代码:
function getAllSeizures_pagination($search_para, $archive_search = FALSE, $result_type)
{
$search_para = $search_para."%";
$selected_fields = "customer.firstName
customer.lastName, customer.address,
customer.city, customer.postcode";
$from = "customer";
$where = "customer.deleted=0 ";
if ($archive_search == TRUE) {
$where .= "AND customer.archived= 1 ";
}else{
$where .= "AND customer.archived= 0 ";
}
$where .= "AND (customer.firstName LIKE '$search_para' OR customer.postcode LIKE '$search_para' OR customer.city LIKE '$search_para')";
$query = $this->db->select($selected_fields, false)
->from($from)
->where($where)
->order_by('customer.idcustomer', 'desc');
if($result_type == "limit_rows")
{
$query = $this->db->limit(10, 0)
->get();
$query = $query->result();
}
if($result_type == "num") {
$query = $this->db->get();
$query = $query->num_rows();
}
return $query;
}
非常感谢
此致 普拉斯
答案 0 :(得分:0)
分页类在指定的uri_segment中将偏移量传递给您。由于您将其设置为3,因此您应该在控制器方法的第一个变量中捕获该信息,如下所示:
function customerlist_pagination( $offset )
{
}
然后,当您致电$this->customers_model->getAllcustomers_pagination()
时,您必须将$offset
传递给它,以便稍后在您的代码中限制您的结果:
$query = $this->db->limit(10, 0)->get();
您应该使用此$offset
来限制结果:
$query = $this->db->limit(10, $offset)->get();