我有一个搜索查询,当我搜索所有类似关键字时,这些记录正在显示匹配的条件,但问题是where子句无效。
$position = $this->session->set_userdata('position', $this->input->post('position'));
$adress_all = explode(",", $this->session->userdata('address'));
$this->db->like('address', $adress_all[0]);
$this->db->or_like('game', $this->session->userdata('skills'));
$this->db->or_like('gender', $this->session->userdata('coach'));
$this->db->or_like('Positions', $this->session->userdata('position'));
$this->db->where('type', 'private');//all other type coaches is also showing up
$sql = $this->db->get('coach');
答案 0 :(得分:2)
您需要使用Grouping LIKE
codeigniter
$this->db->group_start();
$this->db->like('address', $adress_all[0]);
$this->db->or_like('game', $this->session->userdata('skills'));
$this->db->or_like('gender', $this->session->userdata('coach'));
$this->db->or_like('Positions', $this->session->userdata('position'));
$this->db->group_end();
$this->db->where('type', 'private');
$sql = $this->db->get('coach');
希望这有效(需要在您的数据库上进行测试)
答案 1 :(得分:1)
尝试下面的内容。
$this->db->where('type', 'private');//all other type coaches is also showing up
$this->db->where("(address LIKE '%". $adress_all[0]."%' OR game LIKE '%".$this->session->userdata('skills')."%' OR gender LIKE '%".$this->session->userdata('coach')."%' OR positions LIKE '%".$this->session->userdata('position')."%')",null,false);
$sql = $this->db->get('coach');