CI 묻고 답하기

제목 or_like 사용관련 문의
카테고리 CI 2, 3
글쓴이 너구리너구리 작성시각 2018/05/28 11:11:40
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 16705   RSS

안녕하세요.

코드이그나이터 3.x 버전 처음 사용해봤는데요.

쿼리함수중에 or_like 라는게 있더라고요. like를 두개를 해야되는 상황이라 or_like를 사용을 합니다.

근데 where 비교조건이 하나 더 추가되는 형태가 되면 or_like는 무조건 or로 받아들여져서 

type = 1이고, id가 test와 매칭되는 애들을 다 찾아오더라고요.

아래와 같은 사용하고 싶은데 

select * from table where type = 1 and (name like '%test%' or id like '%test%');

or_like를 쓰면 아래처럼 됩니다.

select * from table where type = 1 and name like '%test%' or id like '%test%';

 

혹시 ( ) 추가하는 방법이 있을까요?

 

$this->db->select('id, accessip, regdate, status, logtype');

$this->db->from($tblname)

$this->db->where("logtype", $smsrtype);

if($searchtxt){           

    $this->db->like("lower(id)", $this->db->escape_str($searchtxt));   

    $this->db->or_like("lower(name)", $this->db->escape_str($searchtxt));       

}

 다음글 모델? 질문인것 같습니다.. (1)
 이전글 길이가 긴 배열을 url로 보낼 때 방법 (8)

댓글

곰멍 / 2018/05/28 11:43:45 / 추천 0
너구리너구리 / 2018/05/28 13:20:26 / 추천 0
감사합니다. 저런 바로 적용했습니다.