下面是我的CI控制器代码,用于在查询中添加多个:
$this->load->library('pagination');
$currPage = ($this->uri->segment(4)) ? $this->uri->segment(4) : "" ;
$config['per_page'] = 7;
if($currPage<2)
$currPage = "";
//search
$prjSearch = ($this->uri->segment(3)) ? $this->uri->segment(3) : "" ;
if($prjSearch != "") {
$this->db->like('projectName', $prjSearch, 'after');
$this->db->like('projectName', $prjSearch, 'after');
$this->db->like('projectName', $prjSearch, 'after');
}
$config['base_url'] = $this->config->site_url()."project/index/".$prjSearch."/";
$this->db->select("project.*");
$query = $this->db->get('project',$config['per_page'],$currPage);
$data['data'] = $query->result();
echo $this->db->last_query();
$config['cur_page'] = $data['cur_page'] = $currPage;
$config['uri_segment'] = 4;
//total count
if($prjSearch != "")
$this->db->like('projectName', $prjSearch, 'after');
$query = $this->db->get('project');
$config['total_rows'] = $query->num_rows();
$this->pagination->initialize($config);
生成以下结果:
SELECT `project`.* FROM (`project`) WHERE `projectName` LIKE 'kesh%' AND `projectName` LIKE 'kesh%' AND `projectName` LIKE 'kesh%' LIMIT 7
而不是“AND”之间,我需要“OR”。
我不想使用$this->db->query();
,因为CI会使分页变得复杂或不受支持
任何帮助表示赞赏。
答案 0 :(得分:1)
使用$this->db->or_like
来获取它。所以改变
$this->db->like('projectName', $prjSearch, 'after');
$this->db->like('projectName', $prjSearch, 'after');
$this->db->like('projectName', $prjSearch, 'after');
到这个
$this->db->or_like('projectName', $prjSearch, 'after');
$this->db->or_like('projectName', $prjSearch, 'after');
$this->db->or_like('projectName', $prjSearch, 'after');
答案 1 :(得分:1)
试试这个
$this->db->or_like();
例如:
$this->db->like('title', 'match');
$this->db->or_like('body', $match);
所以在你的情况下,
$this->db->like('projectName', $prjSearch, 'after');
$this->db->or_like('projectName', $prjSearch, 'after');
$this->db->or_like('projectName', $prjSearch, 'after');