병합 : 배열
$where = "lvlOne = '{$par1}'";
$where .= isset($par2)?" AND lvlTwo = '{$par2}'":'';
$where .= isset($par3)?" AND lvlThree = '{$par3}'":'';
내파 : 터너와
$where = "lvlOne = '{$par1}'";
if(isset($par2)) {
$where .= " AND lvlTwo = '{$par2}'";
}
if(isset($par3)) {
$where .= " AND lvlThree = '{$par3}'";
}
병합 작동하고 있다면 비록
//where this one is nice is that regardless of the number of parameters,
//you always end up with the proper 'AND' between each where clause.
$where = array("lvlOne = '{$par1}'");
if(isset($par2)){
$where[] = "lvlTwo = '{$par2}'"
}
if(isset($par3)){
$where[] = "lvlThree = '{$par3}'"
}
$where = impode(' AND ', $where);
결국, 그렇지 거룩한 가증 한 일일 가치있는 대구 e, 왜 그것이 어떻게 생겼는지 걱정하지 않습니까? 그것은 간단한 구문 구조 (예 : 들여 쓰기)를 따릅니다.
편집 : 이미 큰 따옴표 안에 있기 때문에 중괄호로 변수를 둘러싼다고 변경했습니다.
당신은 당신이 쿼리를 작성하는 것처럼 –
이 보이는()는 isset 여러 매개 변수를 전달할 수 있습니다. 왜 이것을 준비하지 않습니까? –
. 일부 플라스틱 쓰레기통, 페인트 칠, 물방울, 시간이 없어 새 것처럼 보일 것입니다. –