CI 묻고 답하기

제목 $this->db->where('') 처리시 case when .. 은 어떻게 구성해야 하는지요.
카테고리 CI 2, 3
글쓴이 하늘을 바라보며 작성시각 2019/10/04 13:38:45
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 15302   RSS

아래와 같이 구성하려고 하는데 잘 안됩니다.

어떻게 하면 좋은지요. 잘 안되는 부분 => where case when  처리

 $this->db->where('여기에 where case when ....

                                                                                      when ....

                                                                            else .. end)

========================================================================================

        $this->db->select(' a.idx as idx, a.send_phon as send_phon, a.recv_phon as recv_phon       

                                               , a.speck_wait_time as speck_wait_time, 중략-- ');

        $this->db->from('intphon_sr a');

        $this->db->join('intphon_sr e', 'a.idx = e.idx');

        $this->db->join('currency h', '1 = 1');

        $this->db->where('여기에 where case when ....

                                                                                      when ....

                                                                            else .. end)

 다음글 헤더 알림 기능 구현 질문드려요 (6)
 이전글 active 레코드에서 사용하는 CI구문들을 프로시져를... (2)

댓글

kaido / 2019/10/04 14:11:26 / 추천 0

$this->db->select( 'query', false);  2번째가 안에 쿼리문을 감싸지 않고 직접 쿼리문을 실행하는 옵션입니다. 기본은 true 입니다.

$this->db->where('조건 1', null, false);    3번째 옵션이 쿼리문을 감싸지 않고 직접 실행 합니다. 기본은true 입니다.

해당 메뉴얼

http://www.ciboard.co.kr/user_guide/kr/database/query_builder.html

하늘을 바라보며 / 2019/10/04 15:35:00 / 추천 0

감사합니다. 덕분에 CI 방식에 맞춰 쿼리를 적용하게되었습니다.

$where = "case
            when (SELECT 중략..
            else h.idx = 1
            end   

            and a.send_date  BETWEEN '{$send_date1}' and '{$send_date2}'
            and a.send_phon < 1000000";

        $this->db->where($where);