내가 Zend_Db의 API의 사용 다음 쿼리를 코딩하는 것을 시도하고있다 : 나는 무엇입니까어디에 사용 IN 절 Zend_Db API를
첫째 :이을 작동하도록하는
select * from tableA where id not in (select pid from tableB where x =46 and y='participated');
나는 다음과 같은 코드를 작성 TableB의에서 배열 형식의 PID의 목록 : 마지막 쿼리가있는 : 이제
$select = $this->select()
->from(array('tb' =>'tableB'), array('mylist' => new Zend_Db_Expr('group_concat(tb.pid)')))
->where('x = ?', $xval) //$xval is coming as 46
->where('type = ?', 'participated');
$result = $this->getAdapter()->fetchAll($select);
error_log("Result of query1 is " . print_r($result, true));
//Convert to array
$mylistArr = preg_split('/,/' , $result[0]['mylist'], PREG_SPLIT_NO_EMPTY);
error_log("value of mylistArr is " . print_r($mylistArr, true));
//Now get the results from tableA
$selectta = $this->select()
->setIntegrityCheck(false)
->from(array('ta' => 'tableA'), array('ta.id', 'ta.first_name', 'ta.last_name'))
->where('ta.id not in (?)', $mylistArr[0]);
$result = $this->fetchAll($selectta);
error_log("db query result is " . print_r($result, true));
는, 문제는 이것이다
SELECT `ta`.`id`, `ta`.`first_name`, `ta`.`last_name` FROM `tableA` AS `ta` WHERE (ta.id not in (197,198,199,200,106,201,202,204,203,205))
이유는 때이다 : 의대 내가 다음과 같이 쿼리 (즉, TableB의에서 아이디의 목록이 인용 부호로 묶어야 안입니다)보고 싶은, 그러나
SELECT `ta`.`id`, `ta`.`first_name`, `ta`.`last_name` FROM `tableA` AS `ta` WHERE (ta.id not in ('197,198,199,200,106,201,202,204,203,205'))
입니다 거꾸로 된 쉼표가 IN 절에서 전달되고 있으며 첫 번째 ID 즉 197 만 결과를 필터링하기 위해 선택됩니다.
정말 도움이됩니다.
감사
당신은 단지 [0] $ mylistArr의 출력을 넣을 수 있습니다?, 왜 대신 preg_split의 내파 사용하지 않는? – jcho360
$ mylistArr [0]의 출력은'[0] => 197,198,199,200106201202204203205'입니다. 함몰을 사용하지 않는 특별한 이유는 없습니다. 그것이 효과를 낼 것입니까? –