sql 여러가지 조건(where) 작동이 안되네요 도와주세요 채택완료
테이블 명 : test2
tag 라는 컬럼에 제품마다 각 각 다른 여러가지 태그 값이 입력이 되어 있습니다.
예) tag: 신선한, 당일배송, 해외배송
아래와 같이 4개의 태그의 검색해서 결과를 보여줘야 하는데요~
아래 $where2 조건이 없으면 $where1 검색이 잘 되는데 $where1 조건이
있으면 결과값이 틀리게 나옵니다.
$where2 변수 안에 조건값은 f_type 컬럼에서 과일 이면서 f_new 컬럼에서 신상품을 가지고 와야 합니다.
그리고 f_name 귤이라는 제품은 무조건 가지고 와야 합니다.
$where1 과 $where2 조건을 동시에 사용하려면 어떻게 해야 하는지 모르겠네요..
</strong>
if(!$tag){$tag="no=no";}
$where1="(tag like '%신선한%' )
or (tag like '%현지직송%' )
or (tag like '%무공해%' )
or (tag like '%국산%' ) ";}</p>
<p> $where2= "and f_type ='과일' and f_new='신상품' or f_name ='귤' ";</p>
<p>
$qr2 = "select * from test2 where $where1 $where2 order by no asc limit 5";
$rt2 = mysqli_query($connect, $qr2);
while($data = mysqli_fetch_array($rt2)){</p>
<p> echo "결과 : ". $data['f_name']." tag: ".$data['tag']." f_new: [".$data['f_new']."]
";</p>
<p><strong>
결과 예)
- 귤 tag: 신선한, 과일 f_new: [신상품]
- 포도 tag: 신선한, 과일, 국산 f_new: [신상품]
- 감 tag: 당일배송, 무공해 f_new: [신상품]
- 사과 tag: 신선한, 과일, 국산 f_new: [신상품]
- 수박 tag: 당일, 현지직송 f_new: [신상품]
이런식으로 나와야 합니다... ㅠㅠ
도와주세욤
답변 4개
추가 피해자 방지 https://sir.kr/conflictconsultation/245" rel="nofollow noreferrer noopener" target="_blank">https://sir.kr/conflictconsultation/245
댓글을 작성하려면 로그인이 필요합니다.
아~ 해결했습니다. https://sir.kr/bbs/profile.php?mb_id=jodw" onclick="return false;" rel="nofollow" target="_blank" title="woong6156 자기소개">woong6156 님 말처럼 $where1 전체를 관호로 넣어 주니까 정상 작동하네요
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
$where1="no=no";
$where1="(tag like '%신선한%' )
or (tag like '%현지직송%' )
or (tag like '%무공해%' )
or (tag like '%국산%' ) ";
$where2= "and f_type ='과일' and f_new='신상품' or f_name ='귤' ";
echo "<결 과><br><br>";
$qr2 = "select * from test2 where $where1 $where2 order by no asc limit 5";
$rt2 = mysqli_query($connect, $qr2);
while($data = mysqli_fetch_array($rt2)){
echo $data['f_name']. " tag: ".$data['tag']." f_new: [".$data['f_new']."]<br>";
}
결과가 아래처럼 나와요 ㅠㅠ
쌀 tag: 가거도, 신선한, 특산품 f_new: [일반]
포도 tag: 신선한, 무공해, 당일 f_new: [신상품]
광어 tag: 제주도, 신선한 f_new: [일반]
귤 tag: 당도100% f_new: [일반]
사과 tag: 신선한 f_new: [신상품]
과일류만 보여야 하며 신상품만 보여야 하는데요~ ㅜ
또 귤은 무조건 보여 하고........