我在使用 CI 分页时遇到问题,这是我的代码。
控制器:
$per_page = 20;
$offset = $this->uri->segment(2);
$results = $this->model_users->search($keywords,$limit = $per_page,$offset,$order_by,$expire,$type = $q_type);
$pagination['per_page'] = $per_page;
$pagination['base_url'] = site_url('users');
$pagination['first_url'] = site_url('users');
$pagination['total_rows'] = $this->db->count_all_results('ci_users');
$pagination['uri_segment'] = 2;
$pagination['first_link'] = 'First';
$pagination['last_link'] = 'Last';
$pagination['next_link'] = false;
$pagination['prev_link'] = false;
$pagination['num_links'] = 6;
$this->pagination->initialize($pagination);
$view['users'] = $results;
该模型:
function search($keywords = false,$limit = false,$offset=false,$order_by = false,$expire = false,$type = 'get'){
if($keywords){
$this->db->select("*,
MATCH(".$type.")
AGAINST ('".$keywords."' IN BOOLEAN MODE)
AS _score",false /*important*/);
$this->db->having('_score > 0');
$this->db->from('ci_users');
$this->db->order_by('_score','DESC');
}else{
$this->db->select('*');
$this->db->from('ci_users');
}
if($expire){
$this->db->order_by('expire_datetime',$expire);
}
if($order_by){
$this->db->order_by("id",$order_by);
}
if($limit){
$this->db->limit($limit,$offset);
}
$query = $this->db->get();
return $query->result();
}
当我单击链接 1 或链接 2 时一切正常,当我单击链接 3 时没有结果返回并且不明白为什么。
使用此代码可以修复,但对站点性能不利,因为我同时运行 2 个搜索查询:
$pagination['total_rows'] = count($this->model_propos->search($keywords,false,false,false ,false,$type = $q_type));
感谢谁会帮助我!