简体   繁体   中英

where clause not working with like query

I have a search query and when I search all like keywords work properly the records are showing with the matched criteria, but the problem is that where clause in not working.

$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');

You need to use Grouping LIKE of 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');

Hope this works(need to test on your DB)

See Doc

Try below things.

$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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM