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();
}
link1 または link2 をクリックするとすべて問題ありませんが、link3 をクリックすると結果が返されず、理由がわかりません。
このコードを使用すると修正されますが、同時に2つの検索クエリを実行しているため、サイトのパフォーマンスには適していません:
$pagination['total_rows'] = count($this->model_propos->search($keywords,false,false,false ,false,$type = $q_type));
私を助けてくれる人に感謝します!!