사이즈를 체크하고 상품명을 넣고 검색하면 해당 사이즈의 상품만 나오게 하는방법
본문
사이즈를 체크하고 상품명을 넣고 검색하면 해당 상품만 나오게 하려고합니다.
상품 등록 부분에 저렇게 채크박스 만들어주고
DB처리하는걸 만들어서
이런식으로 DB에 숫자가 저장되게 만들었습니다.
검색하는 부분은 이렇게 짰는대
예를들어 사이즈 M을 채크 하고 상품명을 넣고 검색하면 M에 해당되는 DB 컬럼 sstype2에는 숫자가 0이라 검색이 되면 안되는대 검색이 되내요 1이면 검색하고 0이면 검색이 안되게 하려고 합니다.
검색부분 전체소스
https://nofile.io/f/8tO5ae7H4Ps/%EC%95%95%EC%B6%95.zip
검색화면 부분
<input type="checkbox" name="it_sttype1" id="it_sttype1" value="1" <?php echo $it_sttype1_check?'checked="checked"':'';?>> <label for="it_sttype1">S</label>
<input type="checkbox" name="it_sttype2" id="it_sttype2" value="1" <?php echo $it_sttype2_check?'checked="checked"':'';?>> <label for="it_sttype2">M</label>
<input type="checkbox" name="it_sttype3" id="it_sttype3" value="1" <?php echo $it_sttype3_check?'checked="checked"':'';?>> <label for="it_sttype3">XL</label>
<input type="checkbox" name="it_sttype4" id="it_sttype4" value="1" <?php echo $it_sttype4_check?'checked="checked"':'';?>> <label for="it_sttype4">XXL</label>
검색 부분
if($_REQUEST['it_sttype1']!=""){
$sizefind.="or it_sttype1='1'";
}
if($_REQUEST['it_sttype2']!=""){
$sizefind.="or it_sttype2='1'";
}
if($_REQUEST['it_sttype3']!=""){
$sizefind.="or it_sttype3='1'";
}
if($_REQUEST['it_sttype4']!=""){
$sizefind.="or it_sttype4='1'";
답변 1
$tmpSize = '';
if($_REQUEST['it_sttype1']!=""){
$tmpSize[] ="it_sttype1='1'";
}
if($_REQUEST['it_sttype2']!=""){
$tmpSize[] ="it_sttype2='1'";
}
if($_REQUEST['it_sttype3']!=""){
$tmpSize[] ="it_sttype3='1'";
}
if($_REQUEST['it_sttype4']!=""){
$tmpSize[] ="it_sttype4='1'";
}
$tmpSize = implode(" or ", $tmpSize);
$sizefind .= "(".$tmpSize.")";