브랜드 검색값을 구해봅니다.
본문
상품입력시 브랜드를 쓸수 있는 입력란이 있던데
사용자 페이지에서 검색시 브랜드도 검색할수 있도록 할수 있을까요?
답변 1
가능합니다
영카트 5.3버전 기준으로..
/shop/search.php
if (isset($_GET['qname']) || isset($_GET['qexplan']) || isset($_GET['qid']) || isset($_GET['qbasic']) || isset($_GET['qbrand']))
$search_all = false;
$q = utf8_strcut(get_search_string(trim($_GET['q'])), 30, "");
$qname = isset($_GET['qname']) ? trim($_GET['qname']) : '';
$qexplan = isset($_GET['qexplan']) ? trim($_GET['qexplan']) : '';
$qid = isset($_GET['qid']) ? trim($_GET['qid']) : '';
$qbasic = isset($_GET['qbasic']) ? trim($_GET['qbasic']) : '';
$qbrand = isset($_GET['qbrand']) ? trim($_GET['qbrand']) : '';
$qcaid = isset($_GET['qcaid']) ? preg_replace('#[^a-z0-9]#i', '', trim($_GET['qcaid'])) : '';
$qfrom = isset($_GET['qfrom']) ? preg_replace('/[^0-9]/', '', trim($_GET['qfrom'])) : '';
$qto = isset($_GET['qto']) ? preg_replace('/[^0-9]/', '', trim($_GET['qto'])) : '';
if (isset($_GET['qsort'])) {
$qsort = trim($_GET['qsort']);
$qsort = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\s]/", "", $qsort);
} else {
$qsort = '';
}
if (isset($_GET['qorder'])) {
$qorder = preg_match("/^(asc|desc)$/i", $qorder) ? $qorder : '';
} else {
$qorder = '';
}
if(!($qname || $qexplan || $qid || $qbasic || $qbrand))
$search_all = true;
// 검색범위 checkbox 처리
$qname_check = false;
$qexplan_check = false;
$qid_check = false;
$qbasic_check = false;
if($search_all) {
$qname_check = true;
$qexplan_check = true;
$qid_check = true;
$qbasic_check = true;
$qbrand_check = true;
} else {
if($qname)
$qname_check = true;
if($qexplan)
$qexplan_check = true;
if($qid)
$qid_check = true;
if($qbasic)
$qbasic_check = true;
if($qbrand)
$qbrand_check = true;
}
if ($q) {
$arr = explode(" ", $q);
$detail_where = array();
for ($i=0; $i<count($arr); $i++) {
$word = trim($arr[$i]);
if (!$word) continue;
$concat = array();
if ($search_all || $qname)
$concat[] = "a.it_name";
if ($search_all || $qexplan)
$concat[] = "a.it_explan2";
if ($search_all || $qid)
$concat[] = "a.it_id";
if ($search_all || $qbasic)
$concat[] = "a.it_basic";
if ($search_all || $qbrand)
$concat[] = "a.it_brand";
$concat_fields = "concat(".implode(",' ',",$concat).")";
$detail_where[] = $concat_fields." like '%$word%' ";
// 인기검색어
insert_popular($concat, $word);
}
$where[] = "(".implode(" and ", $detail_where).")";
}
./skin/shop/search.skin.php
<div class="ssch_right">
<strong class="sound_only">검색범위</strong>
<input type="checkbox" name="qname" id="ssch_qname" value="1" <?php echo $qname_check?'checked="checked"':'';?>> <label for="ssch_qname">상품명</label>
<input type="checkbox" name="qexplan" id="ssch_qexplan" value="1" <?php echo $qexplan_check?'checked="checked"':'';?>> <label for="ssch_qexplan">상품설명</label>
<input type="checkbox" name="qbasic" id="ssch_qbasic" value="1" <?php echo $qbasic_check?'checked="checked"':'';?>> <label for="ssch_qbasic">기본설명</label>
<input type="checkbox" name="qid" id="ssch_qid" value="1" <?php echo $qid_check?'checked="checked"':'';?>> <label for="ssch_qid">상품코드</label>
<input type="checkbox" name="qbrand" id="ssch_brand" value="1" <?php echo $qbrand_check?'checked="checked"':'';?>> <label for="ssch_brand">브랜드</label>
<strong class="sound_only">상품가격 (원)</strong>
<label for="ssch_qfrom" class="sound_only">최소 가격</label>
<input type="text" name="qfrom" value="<?php echo $qfrom; ?>" id="ssch_qfrom" class="ssch_input" size="10"> 원 ~
<label for="ssch_qto" class="sound_only">최대 가격</label>
<input type="text" name="qto" value="<?php echo $qto; ?>" id="ssch_qto" class="ssch_input" size="10"> 원
</div>
<div class="ssch_left">
<label for="ssch_q" class="sound_only" >검색어</label>
<input type="text" name="q" value="<?php echo $q; ?>" id="ssch_q" class="ssch_input" size="40" maxlength="30" placeholder="검색어">
<input type="submit" value="검색" class="btn_submit">
</div>
</div>
강조된 부분을 추가하시면 됩니다.