[수정]검색 페이지에서 여분 필드 추가
본문
상품의 여분 필드를 등록해서 검색 페이지에서 선택할 수 있게 만들려고 하는데요
잘 안됩니다 ㅠㅠ 어찌어찌해서 수정하고 해서 페이지에 체크하게는 하는데 자꾸 체크가 없어지고 검색 결과는
엉뚱하게 전혀 적용이 안되서 나오네요 ㅠㅠ 도와주세요 ㅠㅠ
일단 상품의 여분필드 설정 화면입니다. (여러개 중 일단 4번 필드만 적용해보고 있습니다.)
search.php 파일의 소스입니다. (추가 또는 수정 부분 :88~89)
<?php
include_once('./_common.php');
if(USE_G5_THEME && defined('G5_THEME_PATH')) {
require_once(G5_SHOP_PATH.'/yc/search.php');
return;
}
// QUERY 문에 공통적으로 들어가는 내용
// 상품명에 검색어가 포한된것과 상품판매가능인것만
$sql_common = " from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b ";
$where = array();
$where[] = " (a.ca_id = b.ca_id and a.it_use = 1 and b.ca_use = 1) ";
$search_all = true;
// 상세검색 이라면
if (isset($_GET['qname']) || isset($_GET['qexplan']) || isset($_GET['qid']) || isset($_GET['qtag']))
$search_all = false;
$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'])) : '';
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 || $qtag))
$search_all = true;
// 검색범위 checkbox 처리
$qname_check = false;
$qexplan_check = false;
$qid_check = false;
$qtag_check = false;
if($search_all) {
$qname_check = true;
$qexplan_check = true;
$qid_check = true;
$qtag_check = true;
} else {
if($qname)
$qname_check = true;
if($qexplan)
$qexplan_check = true;
if($qid)
$qid_check = true;
if($qtag)
$qtag_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 || $qtag)
$concat[] = "a.pt_tag";
$concat_fields = "concat(".implode(",' ',",$concat).")";
$detail_where[] = $concat_fields." like '%$word%' ";
// 인기검색어
insert_popular($concat, $word);
}
$where[] = "(".implode(" and ", $detail_where).")";
}
// 분류
$ca_qstr = '';
if ($qcaid) {
$where[] = " a.ca_id like '$qcaid%' ";
$ca_qstr .= '&ca_id='.urlencode($qcaid);
}
if ($qfrom && $qto)
$where[] = " a.it_price between '$qfrom' and '$qto' ";
if ($it_stand)
$where[] = " it_4 = '$it_4' ";
$sql_where = " where " . implode(" and ", $where);
// 상품 출력순서가 있다면
$qsort = strtolower($qsort);
$qorder = strtolower($qorder);
// 아래의 $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';
}
// 분류
$category = array();
$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;
}
// Page ID
$pid = ($pid) ? $pid : 'isearch';
$at = apms_page_thema($pid);
include_once(G5_LIB_PATH.'/apms.thema.lib.php');
// 리스트
$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'];
// 스킨설정
$wset = array();
if($skin_row['search_'.MOBILE_.'set']) {
$wset = apms_unpack($skin_row['search_'.MOBILE_.'set']);
}
// 데모
if($is_demo) {
@include ($demo_setup_file);
}
$skin_path = G5_SKIN_PATH.'/apms/search/'.$skin_name;
$skin_url = G5_SKIN_URL.'/apms/search/'.$skin_name;
// 스킨 체크
list($skin_path, $skin_url) = apms_skin_thema('shop/search', $skin_path, $skin_url);
// 설정값 불러오기
$is_search_sub = false;
@include_once($skin_path.'/config.skin.php');
if(!$list_mods) $list_mods = 3;
if(!$list_rows) $list_rows = 1;
$items = $list_mods * $list_rows;
// 페이지가 없으면 첫 페이지 (1 페이지)
if ($page < 1) $page = 1;
// 시작 레코드 구함
$from_record = ($page - 1) * $items;
// 검색된 내용이 몇행인지를 얻는다
$sql = " select COUNT(*) as cnt $sql_common $sql_where ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$total_page = ceil($total_count / $items); // 전체 페이지 계산
$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--;
}
$admin_href = ($is_admin) ? G5_ADMIN_URL.'/shop_admin/configform.php#anc_scf_etc' : '';
$write_pages = G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'];
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;
$query_string .='&qsort='.$qsort.'&qorder='.$qorder;
$list_page = $_SERVER['SCRIPT_NAME'].'?'.$query_string.'&page=';
$g5['title'] = "상품검색";
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');
}
$lm = 'search'; // 리스트 모드
$ls = $skin_name; // 리스트 스킨
// 셋업
$setup_href = '';
if ($is_demo || $is_designer) {
$setup_href = './skin.setup.php?skin=search&name='.urlencode($ls).'&ts='.urlencode(THEMA);
}
include_once($skin_path.'/search.skin.php');
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');
}
?>
search.skin.form.php의 소스입니다. (추가 또는 수정 부분 :9, 18)
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
?>
<aside>
<form id="frmdetailsearch" name="frmdetailsearch" class="form-horizontal" role="form">
<input type="hidden" name="qsort" id="qsort" value="<?php echo $qsort ?>">
<input type="hidden" name="qorder" id="qorder" value="<?php echo $qorder ?>">
<input type="hidden" name="qcaid" id="qcaid" value="<?php echo $qcaid ?>">
<input type="hidden" name="it_stand" id="it_stand0" value="<?php echo $it_stand ?>">
<div class="search-box" style="padding-bottom:0px;">
<div class="form-group">
<label class="col-sm-2 control-label hidden-xs"><b>검색범위</b></label>
<div class="col-sm-10">
<label class="control-label label-sp"><input type="checkbox" name="qname" id="ssch_qname" value="1" <?php echo $qname_check?'checked="checked"':'';?>> 제목</label>
<label class="control-label label-sp"><input type="checkbox" name="qexplan" id="ssch_qexplan" value="1" <?php echo $qexplan_check?'checked="checked"':'';?>> 설명</label>
<label class="control-label label-sp"><input type="checkbox" name="qid" id="ssch_qid" value="1" <?php echo $qid_check?'checked="checked"':'';?>> 코드</label>
<label class="control-label label-sp"><input type="checkbox" name="qtag" id="ssch_qtag" value="1" <?php echo $qtag_check?'checked="checked"':'';?>> 태그</label>
<label class="control-label"><input type="checkbox" name="it_stand" id="it_stand0" value="1" <?php echo get_checked($it_stand, '1'); ?>> 스탠드</label>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label hidden-xs"><b>상품가격 (원)</b></label>
<div class="col-sm-10">
<label for="ssch_qfrom" class="sound_only">최소 가격</label>
<label class="label-none">
<input type="text" name="qfrom" value="<?php echo $qfrom; ?>" id="ssch_qfrom" class="form-control input-sm" size="10" placeholder="최소 가격">
</label>
<label> ~ </label>
<label for="ssch_qto" class="sound_only">최대 가격</label>
<label class="label-none">
<input type="text" name="qto" value="<?php echo $qto; ?>" id="ssch_qto" class="form-control input-sm" size="10" placeholder="최대 가격">
</label>
</div>
</div>
<div class="form-group">
<label for="ssch_q" class="col-sm-2 control-label hidden-xs"><b>검색어</b></label>
<div class="col-sm-4 col-xs-6">
<input type="text" name="q" value="<?php echo $q; ?>" id="ssch_q" class="form-control input-sm" size="40" maxlength="30" placeholder="검색어">
</div>
<div class="col-sm-3 col-xs-6">
<button type="submit" class="btn btn-<?php echo $btn2;?> btn-block btn-sm"><i class="fa fa-search fa-lg"></i> 검색하기</button>
</div>
</div>
<div class="form-group">
<label for="ssch_q" class="col-sm-2 control-label hidden-xs"><b>검색안내</b></label>
<div class="col-sm-10">
검색범위을 선택하지 않거나, 상품가격을 입력하지 않으면 전체에서 검색합니다.<br>
검색어는 최대 30글자까지, 여러개의 검색어를 공백으로 구분하여 입력 할수 있습니다.
</div>
</div>
</div>
</form>
<script>
function set_sort(qsort) {
var f = document.frmdetailsearch;
var qorder = "desc";
if(qsort == "it_price_min") {
qsort = "it_price";
qorder = "asc";
}
f.qsort.value = qsort;
f.qorder.value = qorder;
f.submit();
}
function set_ca_id(qcaid) {
var f = document.frmdetailsearch;
f.qcaid.value = qcaid;
f.submit();
}
</script>
</asde>
<aside>
<div class="row">
<div class="col-sm-3">
<div class="form-group input-group input-group-sm">
<span class="input-group-addon"><i class="fa fa-tag"></i></span>
<select name="sortodr" onchange="set_ca_id(this.value); return false;" class="form-control input-sm">
<option value="">전체분류(<?php echo number_format($total_count);?>)</option>
<?php for($i=0;$i < count($category); $i++) { ?>
<option value="<?php echo $category[$i]['ca_id'];?>"<?php echo ($qcaid === $category[$i]['ca_id']) ? ' selected' : '';?>><?php echo $category[$i]['ca_name'];?>(<?php echo number_format($category[$i]['cnt']);?>)</option>
<?php } ?>
</select>
</div>
</div>
<div class="col-sm-6">
</div>
<div class="col-sm-3">
<div class="form-group input-group input-group-sm">
<span class="input-group-addon"><i class="fa fa-sort"></i></span>
<select name="sortodr" onchange="set_sort(this.value); return false;" class="form-control input-sm">
<option value="">정렬하기</option>
<option value="it_sum_qty"<?php echo ($qsort == 'it_sum_qty') ? ' selected' : '';?>>판매많은순</option>
<option value="it_price_min"<?php echo ($qsort == 'it_price' && $qorder == 'asc') ? ' selected' : '';?>>낮은가격순</option>
<option value="it_price"<?php echo ($qsort == 'it_price' && $qorder == 'desc') ? ' selected' : '';?>>높은가격순</option>
<option value="it_use_avg"<?php echo ($qsort == 'it_use_avg') ? ' selected' : '';?>>평점높은순</option>
<option value="it_use_cnt"<?php echo ($qsort == 'it_use_cnt') ? ' selected' : '';?>>후기많은순</option>
<option value="pt_good"<?php echo ($qsort == 'pt_good') ? ' selected' : '';?>>추천많은순</option>
<option value="pt_comment"<?php echo ($qsort == 'pt_comment') ? ' selected' : '';?>>댓글많은순</option>
<option value="it_update_time"<?php echo ($qsort == 'it_update_time') ? ' selected' : '';?>>최근등록순</option>
</select>
</div>
</div>
</div>
</aside>
!-->!-->
답변 2
다중검색 또는 복합검색 이라고 치시면 제 게시물중에서 비슷한 내용이 있는데요
여분필드를 쪼개서 값을 여러개 넣고 채크박스로 원하는 값만 검색되게 하는 기능입니다.
이거 응용하시면 되실것 같아요.
http://sir.kr/qa/?unanswered=&sst=wr_num&s_tag=&stx=%EB%8B%A4%EC%A4%91%EA%B2%80%EC%83%89
요기서 제 아이디 질문글만 보시면되세요~
답변을 작성하시기 전에 로그인 해주세요.