검색 필드 질문

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
검색 필드 질문

QA

검색 필드 질문

본문

주문 내역에서 검색 필드를

 

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

 

이렇게 해결했습니다

답변을 작성하시기 전에 로그인 해주세요.
전체 60,014
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT