검색 필드 질문

검색 필드 질문

QA

검색 필드 질문

답변 1

본문

주문 내역에서 검색 필드를

 

if ($where) {
    $sql_search = ' where '.implode(' and ', $where);
}

if ($where2) {
    $sql_search = ' where '.implode(' or ', $where2);
}

 

이렇게 설정하였는데요

 

각각 따로따로 검색 필드를 활용할 때는 문제가 없는데 where와 where2가 공존하게 되면 문제가 발생하네요

 

if ($where && $where2) {
    $sql_search = ' where '.(implode(' or ', $where2)).implode(' and ', $where);
} else if ($where) {
    $sql_search = ' where '.implode(' and ', $where);
} else if ($where2) {
    $sql_search = ' where '.implode(' or ', $where2);
}

이렇게 하니까 결과가 안나오네요 ㅠㅠ

이렇게 해도 각각 한 필드만 쓰면 문제 없이 잘 나옵니다

 

어떻게 하면 좋을까요?

 

이 질문에 댓글 쓰기 :

답변 1

자문자답합니다 ㅠㅠ

 

$sql_or = " ( " . implode(" or ", $where2) . " ) ";
if ($where && $where2) {
    $sql_search = ' where '.$sql_or.' and'.implode(' and ', $where);
} else if ($where) {
    $sql_search = ' where '.implode(' and ', $where);
} else if ($where2) {
    $sql_search = ' where '.implode(' or ', $where2);
}

 

이렇게 해결했습니다

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로