2017-12-16 12 views
-1

이것은 쿼리에서 FIND_IN_SET을 사용하는 방법으로 자동으로 쿼리에서 IS NULL을 추가하고 이후에 대괄호를 추가해야합니다 WHERE s. cat_id = '11'AND 쿼리FIND_IN_SET 자동으로 codeigniter의 쿼리에 IS NULL을 추가하고 그룹을 만들기 위해 쿼리에 대괄호를 추가해야합니다.

$spilt=explode(',',$newstyle); 

foreach ($spilt as $splitkey => $splitvalue) { 
    if ($splitkey == 0) { 
     $this->db->where("FIND_IN_SET(".$splitvalue.",w_card_style)"); 
    } 
    else{ 
     $this->db->or_where("FIND_IN_SET(".$splitvalue.",w_card_style)"); 
    } 
} 

$this->db->last_query()를 사용하여 쿼리를 인쇄이 후

SELECT `c`.`city_name`, `s`.`name`, `s`.`location`, `s`.`starting_price`, `s`.`budget_range`, `s`.`cat_id`, `s`.`id`, `i`.`path`, `s`.`specification_status`, `s`.`per_unit_charge`, `s`.`w_card_style`, `s`.`w_card_style`, `s`.`budget_range` FROM `image_gallery` as `i` JOIN `specification` as `s` ON `i`.`ser_id`=`s`.`id` JOIN `cities` as `c` ON `c`.`city_id`=`s`.`location` JOIN `wcard_style` as `ws` ON `ws`.`id`=`s`.`w_card_style` WHERE `s`.`cat_id` = '11' AND FIND_IN_SET(1,w_card_style) IS NULL OR FIND_IN_SET(2,w_card_style) IS NULL OR FIND_IN_SET(3,w_card_style) IS NULL AND budget_range BETWEEN 50 AND 100 GROUP BY `ser_id` HAVING `cat_id` = '11' ORDER BY `s`.`budget_range` DESC 

추천 검색어를 제공 각각 존재 FIND_IN_SET는 NULL이므로 얼마나 제거하려면 쿼리에서 NULL IS 또한이

SELECT `c`.`city_name`, `s`.`name`, `s`.`location`, `s`.`starting_price`, `s`.`budget_range`, `s`.`cat_id`, `s`.`id`, `i`.`path`, `s`.`specification_status`, `s`.`per_unit_charge`, `s`.`w_card_style`, `s`.`w_card_style`, `s`.`budget_range` FROM `image_gallery` as `i` JOIN `specification` as `s` ON `i`.`ser_id`=`s`.`id` JOIN `cities` as `c` ON `c`.`city_id`=`s`.`location` JOIN `wcard_style` as `ws` ON `ws`.`id`=`s`.`w_card_style` WHERE `s`.`cat_id` = '11' AND (FIND_IN_SET(1,w_card_style) IS NULL OR FIND_IN_SET(2,w_card_style) IS NULL OR FIND_IN_SET(3,w_card_style) IS NULL) AND budget_range BETWEEN 50 AND 100 GROUP BY `ser_id` HAVING `cat_id` = '11' ORDER BY `s`.`budget_range` DESC`enter code here` 
+2

의 정확한 복제 ([CodeIgniter의은 첨가가 발견 \ 유념하라 \ _set의 null] https://stackoverflow.com/questions/33390038/codeigniter-adding-the-is-null-in-the- find-in-set) – mickmackusa

답변

0

같은 실행에 시간이 다 시도 "s. cat_id = '11'AND이 WHERE"후 브라켓을 추가 할 필요가 ode 일부 chnages.Use 귀하의 코드를 사용하여 아래 코드를 작동하도록 수정했습니다.

$spilt=explode(',',$newstyle); 
      foreach ($spilt as $splitkey => $splitvalue) { 
      if ($splitkey == 0) { 
      $this->db->where("FIND_IN_SET(".$splitvalue.",w_card_style)!=",0); 
      } 
      else{ 
       $this->db->or_where("FIND_IN_SET(".$splitvalue.",w_card_style)!=",0); 
      } 
      } 
+0

덕분에 @tarangpatel, 그것은 나를 위해 작동합니다. –