0
Hy, Zend_Db_Select와 관련된 몇 가지 문제점이 있습니다. 카테고리와 도시라는 두 개의 변수가 있습니다. 이 2 개의 변수는 값을 가질 수도 있고 설정되지 않을 수도 있습니다. 그래서 확인 :Zend_Db_Select : multiple from 절
$status = '`p`.status = 1';
if($catID){
$catSQL = "`p`.parent = {$catID}";
}else{
$catSQL = '1=1';
}
if($city){
$citySQL = "`pm`.`meta_key` = 'oras' and `pm`.`meta_value` = {$city}";
$citySelect = array('pm' => 'postsmeta');
$condCity = "`p`.`ID` = `pm`.`parent_id`";
}else{
$citySQL = '1=1';
$citySelect = NULL;
$condCity = '1=1';
}
지금 여기 내 쿼리입니다 :
$select = $db->select()
->from(array('p' => 'posts'))
->from($citySelect)
->where($status)
->where($catSQL)
->where($condCity)
->where($citySQL)
;
문제는 도시가 비어있는 경우 내가 어떻게 할 수
$select = $db->select()
->from(array('p' => 'posts'))
->from('')
->where(1=1)
->where(1=1)
->where(1=1)
->where(1=1)
;
질문 같은 것을되고있다이다 도시가 비어 있으면 내 검색어에서 ('')을 삭제하십시오. 감사합니다.
$select = $db->select()
->from(array('p' => 'posts'));
if($someConditionIsTrue) {
$select->join($table, $condition);
}
$select->where('field_value = ?', 'value1');
if($someConditionIsTrue) {
$select->where('another_field = ?', 'value 2');
}
간단히