테스트 사이트 - 개발 중인 베타 버전입니다

검색 필드 질문 채택완료

블랑숑 4년 전 조회 1,768

주문 내역에서 검색 필드를

 

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개

4년 전

자문자답합니다 ㅠㅠ

 

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

 

이렇게 해결했습니다

로그인 후 평가할 수 있습니다

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

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

로그인