상품 검색 시 전체분류 오류 채택완료
블랑숑
9년 전
조회 3,228
http://loamytek03.cafe24.com/shop/search.php">http://loamytek03.cafe24.com/shop/search.php
를 가보시고 그냥 검색하기를 누르면 제품이 달랑 2개 입력이 되어 있습니다. 카테고리도 1개의 카테고리에만 등록이 되어 있구요.
그런데 다중검색을 하여 프레임스타일 -> 알루미늄, 오크목을 동시 체크하고 검색을 하면 모든 카테고리에 상품이 하나씩 있는 것처럼 계속 중복되어 나옵니다.
무엇이 문제일까요? ㅠㅠ
search.php의 소스 전문을 올려볼게요 제품 종류는 it_1과 관련이 있으며 프레임스타일은 it_5와 관련이 있어요.
</p><p><?php
include_once('./_common.php');</p><p>if(USE_G5_THEME && defined('G5_THEME_PATH')) {
require_once(G5_SHOP_PATH.'/yc/search.php');
return;
}</p><p>// QUERY 문에 공통적으로 들어가는 내용
// 상품명에 검색어가 포한된것과 상품판매가능인것만
$sql_common = " from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b ";</p><p>$where = array();
$where[] = " (a.ca_id = b.ca_id and a.it_use = 1 and b.ca_use = 1) ";</p><p>$search_all = true;
// 상세검색 이라면
if (isset($_GET['qname']) || isset($_GET['qexplan']) || isset($_GET['qid']) || isset($_GET['qtag']))
$search_all = false;</p><p>$q = ($stx) ? $stx : $_GET['q'];
$qname = isset($_GET['qname']) ? trim($_GET['qname']) : '';
$qexplan = isset($_GET['qexplan']) ? trim($_GET['qexplan']) : '';
$qid = isset($_GET['qid']) ? trim($_GET['qid']) : '';
$qtag = isset($_GET['qtag']) ? trim($_GET['qtag']) : '';
$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'])) : '';
$wfrom = isset($_GET['wfrom']) ? preg_replace('/[^0-9]/', '', trim($_GET['wfrom'])) : '';
$wto = isset($_GET['wto']) ? preg_replace('/[^0-9]/', '', trim($_GET['wto'])) : '';
$hfrom = isset($_GET['hfrom']) ? preg_replace('/[^0-9]/', '', trim($_GET['hfrom'])) : '';
$hto = isset($_GET['hto']) ? preg_replace('/[^0-9]/', '', trim($_GET['hto'])) : '';
if (isset($_GET['qsort'])) {
$qsort = trim($_GET['qsort']);
$qsort = preg_replace("/[\<\>\'\"<a>\\\'\\\"\%\=\(\)\s]/</a>", "", $qsort);
} else {
$qsort = '';
}
if (isset($_GET['qorder'])) {
$qorder = preg_match("/^(asc|desc)$/i", $qorder) ? $qorder : '';
} else {
$qorder = '';
}</p><p>if(!($qname || $qexplan || $qid || $qtag))
$search_all = true;</p><p>// 검색범위 checkbox 처리
$qname_check = false;
$qexplan_check = false;
$qid_check = false;
$qtag_check = false;
$it_4_check = false;</p><p>
if($search_all) {
$qname_check = true;
$qexplan_check = true;
$qid_check = true;
$qtag_check = true;
$it_4_check = false;
} else {
if($qname)
$qname_check = true;
if($qexplan)
$qexplan_check = true;
if($qid)
$qid_check = true;
if($qtag)
$qtag_check = true;
if($it_4)
$it_4_check = true;
}</p><p>if ($q) {
$arr = explode(" ", $q);
$detail_where = array();
for ($i=0; $i<count($arr); $i++) {
$word = trim($arr[$i]);
if (!$word) continue;</p><p> $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 || $qtag)
$concat[] = "a.pt_tag";
$concat_fields = "concat(".implode(",' ',",$concat).")";</p><p> $detail_where[] = $concat_fields." like '%$word%' ";</p><p> // 인기검색어
insert_popular($concat, $word);</p><p> }</p><p> $where[] = "(".implode(" and ", $detail_where).")";
}</p><p> </p><p>if ($it_2)
$where[] = " it_2 = '$it_2' ";</p><p>if ($it_3)
$where[] = " it_3 = '$it_3' "; </p><p>if ($it_4)
$where[] = " it_4 = '$it_4' ";</p><p>if ($it_6)
$where[] = " it_6 = '$it_6' ";</p><p>if ($it_7)
$where[] = " it_7 = '$it_7' "; </p><p> </p><p>foreach ($it_1 as $k => $v) {</p><p> if ($v == '') break;</p><p> $str[] = " a.it_1 = '" . $v . "'";</p><p>}</p><p>if (isset($str)) $where[] = implode(' or ', $str);</p><p>
foreach ($it_5 as $k => $v) {</p><p> if ($v == '') break;</p><p> $str[] = " a.it_5 = '" . $v . "'";</p><p>}</p><p>if (isset($str)) $where[] = implode(' or ', $str);</p><p> </p><p>// 분류
$ca_qstr = '';
if ($qcaid) {
$where[] = " a.ca_id like '$qcaid%' ";
$ca_qstr .= '&ca_id='.urlencode($qcaid);
}</p><p>if ($qfrom && $qto)
$where[] = " a.it_price between '$qfrom' and '$qto' ";</p><p>if ($wfrom && $wto) {
$where[] = " a.it_6 between '$wfrom' and '$wto' ";
} else if($wfrom) {
$where[] = " a.it_6 >= '$wfrom' ";
} else if($wto) {
$where[] = " a.it_6 <= '$wfrom' ";
}</p><p>if ($hfrom && $hto) {
$where[] = " a.it_7 between '$hfrom' and '$hto' ";
} else if($hfrom) {
$where[] = " a.it_7 >= '$hfrom' ";
} else if($hto) {
$where[] = " a.it_7 <= '$hfrom' ";
}</p><p>$sql_where = " where " . implode(" and ", $where);</p><p>// 상품 출력순서가 있다면
$qsort = strtolower($qsort);
$qorder = strtolower($qorder);</p><p>// 아래의 $qsort 필드만 정렬이 가능하게 하여 다른 필드로 하여금 유추해 볼수 없게함
if (($qsort == "it_sum_qty" || $qsort == "it_price" || $qsort == "it_use_avg" || $qsort == "it_use_cnt" || $qsort == "it_update_time" || $qsort == "pt_good" || $qsort == "pt_comment") &&
($qorder == "asc" || $qorder == "desc")) {
$order_by = ' order by ' . $qsort . ' ' . $qorder . ' , it_order, pt_num desc, it_id desc';
} else {
$order_by = ' order by it_order, pt_num desc, it_id desc';
}</p><p>// 분류
$category = array();</p><p>$sql = " select b.ca_id, b.ca_name, count(*) as cnt $sql_common $sql_where group by b.ca_id order by b.ca_id ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$category[$i] = $row;
}</p><p>// Page ID
$pid = ($pid) ? $pid : 'isearch';
$at = apms_page_thema($pid);
include_once(G5_LIB_PATH.'/apms.thema.lib.php');</p><p>// 리스트
$list = array();
$skin_row = array();
$skin_row = apms_rows('search_'.MOBILE_.'set');
$skin_name = $default['de_'.MOBILE_.'search_list_skin'];
$thumb_w = $default['de_'.MOBILE_.'search_img_width'];
$thumb_h = $default['de_'.MOBILE_.'search_img_height'];
$list_mods = $default['de_'.MOBILE_.'search_list_mod'];
$list_rows = $default['de_'.MOBILE_.'search_list_row'];</p><p>// 스킨설정
$wset = array();
if($skin_row['search_'.MOBILE_.'set']) {
$wset = apms_unpack($skin_row['search_'.MOBILE_.'set']);
}</p><p>// 데모
if($is_demo) {
@include ($demo_setup_file);
}</p><p>$skin_path = G5_SKIN_PATH.'/apms/search/'.$skin_name;
$skin_url = G5_SKIN_URL.'/apms/search/'.$skin_name;</p><p>// 스킨 체크
list($skin_path, $skin_url) = apms_skin_thema('shop/search', $skin_path, $skin_url); </p><p>// 설정값 불러오기
$is_search_sub = false;
@include_once($skin_path.'/config.skin.php');</p><p>if(!$list_mods) $list_mods = 3;
if(!$list_rows) $list_rows = 1;</p><p>$items = $list_mods * $list_rows;</p><p>// 페이지가 없으면 첫 페이지 (1 페이지)
if ($page < 1) $page = 1;</p><p>// 시작 레코드 구함
$from_record = ($page - 1) * $items;</p><p>// 검색된 내용이 몇행인지를 얻는다
$sql = " select COUNT(*) as cnt $sql_common $sql_where ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$total_page = ceil($total_count / $items); // 전체 페이지 계산</p><p>$num = $total_count - ($page - 1) * $items;
$result = sql_query(" select * $sql_common $sql_where {$order_by} limit $from_record, $items ");
for ($i=0; $row=sql_fetch_array($result); $i++) {
$list[$i] = $row;
$list[$i]['href'] = './item.php?it_id='.$row['it_id'].$ca_qstr;
$list[$i]['num'] = $num;
$num--;
}</p><p>$admin_href = ($is_admin) ? G5_ADMIN_URL.'/shop_admin/configform.php#anc_scf_etc' : '';</p><p>$write_pages = G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'];</p><p>if($search_all) {
$qname = $qexplan = $qid = $qtag = 1;
}
$query_string = 'ca_id='.$ca_id.'&q='.urlencode($q);
$query_string .= '&qname='.$qname.'&qexplan='.$qexplan.'&qid='.$qid.'&qtag='.$qtag.'&';
if($qcaid) $query_string .= '&qcaid='.$qcaid;
if($qfrom && $qto) $query_string .= '&qfrom='.$qfrom.'&qto='.$qto;
if($wfrom && $wto) $query_string .= '&wfrom='.$wfrom.'&wto='.$wto;
if($hfrom && $hto) $query_string .= '&hfrom='.$qfrom.'&hto='.$hto;
$query_string .='&qsort='.$qsort.'&qorder='.$qorder;</p><p>$list_page = $_SERVER['SCRIPT_NAME'].'?'.$query_string.'&page=';</p><p>$g5['title'] = "상품검색";</p><p>if($is_search_sub) {
include_once(G5_PATH.'/head.sub.php');
if(!USE_G5_THEME) @include_once(THEMA_PATH.'/head.sub.php');
} else {
include_once('./_head.php');
}</p><p>$lm = 'search'; // 리스트 모드
$ls = $skin_name; // 리스트 스킨</p><p>// 셋업
$setup_href = '';
if ($is_demo || $is_designer) {
$setup_href = './skin.setup.php?skin=search&name='.urlencode($ls).'&ts='.urlencode(THEMA);
}</p><p>include_once($skin_path.'/search.skin.php');</p><p>if($is_search_sub) {
if(!USE_G5_THEME) @include_once(THEMA_PATH.'/tail.sub.php');
include_once(G5_PATH.'/tail.sub.php');
} else {
include_once('./_tail.php');
}
?></p><p>
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
9년 전
라인 189번째 밑에
echo " select * as cnt $sql_common $sql_where ";
찍어보세요.
sql문을 보시면, 어디가 잘못됐는지 알수 있어요.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
�
블랑숑
9년 전
select * 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)
�
블랑숑
9년 전
요렇게 나오네요 ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인