검색할때 검색어랑 브랜드랑 같이 검색되게 하고 싶습니다.
본문
검색 카테고리를 직접 만들었는데 검색창에 검색어를 입력하고 난 후 카테고리에 있는 브랜드 명을 누르면 검색이 안됩니다. sql 문을 살펴봤는데 검색어만 검색했을 때는 concat() 안에 있는 변수들(a.it_name, a.it_explan2, a.it_id, a.it_basic) 로 select 문이 돌아가는데 그 이후 브랜드 명을 누르면 concat() 안에 있는 변수들이 사라져서 select 됩니다.
select b.ca_id, b.ca_name, count(*) as cnt from g5_shop_item a, g5_shop_category b where (a.ca_id = b.ca_id and a.it_use = 1 and b.ca_use = 1) and (concat() like '%노트북%' ) and a.it_brand like '삼성%' group by b.ca_id order by b.ca_id
// 이 코드가 검색어와 브랜드를 같이 검색했을 때 나오는 sql 문입니다.
// $q가 검색어입니다
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";
$concat_fields = "concat(".implode(",' ',",$concat).")";
$detail_where[] = $concat_fields." like '%$word%' ";
// 인기검색어
insert_popular($concat, $word);
}
$where[] = "(".implode(" or ", $detail_where).")";
}
//브랜드 검색
if ($qbrand)
$where[] = " a.it_brand like '$qbrand%' ";
skin에서는
<a href="#n" onclick = "set_it_brand('삼성')">삼성</a>
function set_it_brand(qbrand) //브랜드
{
var f = document.frmdetailsearch;
f.qbrand.value = qbrand;
f.submit();
}
concat()안에 있는 변수들이 왜 사라질까요,.,????????????
!-->!-->답변 4
if ($search_all || $qbrand )
$concat[] = "a.it_brand";
이렇게도 해 보세요.
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";
$concat_fields = "concat(".implode(",' ',",$concat).")";
$detail_where[] = $concat_fields." like '%$word%' ";
// 인기검색어
insert_popular($concat, $word);
}
//브랜드 검색
if ($qbrand) $detail_where[] = " a.it_brand like '$qbrand%' ";
$where[] = "(".implode(" or ", $detail_where).")";
}
위 코드처럼 해보세요. 단, 검색어가 있을때 브랜드도 같이 추출하는 조건입니다.
!-->다들 감사합니다! if($search_all || $qname) 이부분이 제가 받아오는 변수랑 달랐어서 안되는거였어요 ㅠㅠ
도움 주셔서 감사합니다!
답변을 작성하시기 전에 로그인 해주세요.