미채택 완료

검색 필드 질문

2020-12-30 (수) 19:48:00 1,882

주문 내역에서 검색 필드를

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개

2020-12-30 (수) 20:11:13

자문자답합니다 ㅠㅠ

$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);
}

이렇게 해결했습니다

답변을 작성하려면 로그인이 필요합니다.