다중검색 질문 드립니다. 채택완료
밀크가이
10년 전
조회 4,383
검색 get 으로 봤을때 &info01=회관&info01=기타공간
이런 형태로 검색값이 넘어가고 있구요.
예를 들어서 사용자페이지에서
회관 이나 기타공간 하나씩 체크하면 검색이 되는데
다중으로 둘다 체크 했을때는 검색이 안되는데요.. 조언 좀 부탁드립니다.
머..회관기타공간 이렇게 연달아서 인식을 해서 그런지...그래도 like 에서 %% 로 감싸면
단어가 해당되면 다 나오지 않나요...
자료 등록할 때는 ca_3 값으로 라디오로 등록됩니다.
아래는 검색결과페이지 sql 구문 입니다.
</p><p>$where = " and "; </p><p>$sql_search = ""; </p><p>$ca_addr = $ca_10 = $in1 = $in2 = '';</p><p> </p><p>if(trim($sido)) { </p><p>$stx2 = $sido.' '.$gugun; </p><p>$ca_addr = " and ca_addr1 like '%$stx2%' "; </p><p>}</p><p>if($gugun == '전체') {</p><p>$stx2 = $sido; </p><p>$ca_addr = " and ca_addr1 like '%$stx2%' "; </p><p>}</p><p> </p><p>if(trim($pe_start) && trim($pe_end)) { </p><p><span class="Apple-tab-span" style="white-space:pre"> </span></p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$ca_10 = " and ca_10 BETWEEN $pe_start AND $pe_end "; </p><p> </p><p>}</p><p>else if(trim($pe_start)) { </p><p><span class="Apple-tab-span" style="white-space:pre"> </span></p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$ca_10 = " and ca_10 BETWEEN 1 AND $pe_start "; </p><p> </p><p>}</p><p>else if(trim($pe_end)) { </p><p><span class="Apple-tab-span" style="white-space:pre"> </span></p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$ca_10 = " and ca_10 BETWEEN 1 AND $pe_end "; </p><p> </p><p>}</p><p> </p><p> </p><p>if($info01 || $info02) {</p><p> </p><p>$stx8 = $info01;</p><p>$stx9 = $info02;</p><p> </p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$in1 = " and ca_3 like '%$stx8%' ";</p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$in2 = " and ca_20 like '%$stx9%' ";</p><p> </p><p>}</p><p> </p><p> </p><p>if ($stx != "") { </p><p> if ($sfl != "") { </p><p> $sql_search .= " $where $sfl like '%$stx%' $ca_addr $ca_10 $in1 $in2 "; </p><p> $where = " and "; </p><p> } </p><p> </p><p> </p><p>} else {</p><p> </p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$sql_search .= " $ca_addr $ca_10 $in1 $in2 "; </p><p> </p><p>} </p><p>
핵심은.. 하나씩 체크하면 잘 되는데.. 중복으로 체크하면 먹히질 않고 있습니다.
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
10년 전
질문 올리실때 해당 url이나 좀 길게 되더라도 가급적 검색폼(html)과 처리(php) 소스 모두를 보여주시는게 좋겠습니다.
예전 질문에서 사이트를 본 기억이 있어서 뒤적거려서 들어가봤는데요..
장소유형, 체육시설, 특별 대관장소는 info01 => ca_3
실내 좌석 배치 info02 => ca_20
특수 검색 info03 => ??
이렇게 되있던데 맞는건가요?
info03은 위의 소스에서 아예 안보이는데 어떤식으로 검색되고 있는건지 모르겠군요.
여튼.. 지금의 방법으로는 info01중 마지막 체크된 것만 검색할겁니다.
검색폼에서 이 부분들중 name에 넣는 값을 배열로 바꿔보세요.
</div><div><input type="checkbox" name="info01[]" value="호텔"></div><div>
각각 info01~03 모두 name값 뒤에 [] 이걸 붙이면 php에서 받을때 배열값으로 받게됩니다.
그에따른 처리도 바뀌어야합니다.
위의 소스중 31~39 라인 수정
</div><div>$in1 = $in2 = '';</div><div>if(count($info01)) {</div><div> foreach($info01 as $value) {</div><div> $in1 .= " and ca_3 like '%$value%' ";</div><div> }</div><div>}</div><div>if(count($info02)) {</div><div> foreach($info02 as $value) {</div><div> $in2 .= " and ca_20 like '%$value%' ";</div><div> }</div><div>}</div><div>
이렇게하면 체크한 키워드 모두 검색할 겁니다.
info03은 따로 언급이 없어서(필드명을 몰라서) 안넣었는데요, 필요하면 위처럼 추가해서 넣으시면 될겁니다.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 3개
�
밀크가이
10년 전
�
먼지손
10년 전
아이고 제가 큰 실수를 했네요;;
[code]
$in1 = $in2 = array;
if(count($info01)) {
foreach($info01 as $value) {
$in1[] = " ca_3 like '%$value%' ";
}
}
$in1 = implode(' or ', $in1);
if($in1) $in1 = " and ($in1) ";
if(count($info02)) {
foreach($info02 as $value) {
$in2[] = " ca_20 like '%$value%' ";
}
}
$in2 = implode(' or ', $in2);
if($in2) $in2 = " and ($in2) ";
[/code]
[code]
$in1 = $in2 = array;
if(count($info01)) {
foreach($info01 as $value) {
$in1[] = " ca_3 like '%$value%' ";
}
}
$in1 = implode(' or ', $in1);
if($in1) $in1 = " and ($in1) ";
if(count($info02)) {
foreach($info02 as $value) {
$in2[] = " ca_20 like '%$value%' ";
}
}
$in2 = implode(' or ', $in2);
if($in2) $in2 = " and ($in2) ";
[/code]
�
밀크가이
10년 전
오류가 나서
$in1 = $in2 = array; -- > $in1 = $in2 = array();
수정 후 정상작동 합니다!!
많은 도움 주셔서 감사하고.. 많이 배웁니다..^^
$in1 = $in2 = array; -- > $in1 = $in2 = array();
수정 후 정상작동 합니다!!
많은 도움 주셔서 감사하고.. 많이 배웁니다..^^
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
info03 은 필드자체가 없어서 임시로 해놓은거라 신경 안쓰셔도 됩니다..
html 도 같이 올려봅니다..
[code]
<tr>
<td class="head">체육시설</td>
<td>
<ul>
<li>
<label for="info01" class="sound_only">운동장</label>
<input type="checkbox" name="info01[]" value="운동장"> 운동장
</li>
<li>
<label for="info01" class="sound_only">야구장</label>
<input type="checkbox" name="info01[]" value="야구장"> 야구장
</li>
<li>
<label for="info01" class="sound_only">체육관</label>
<input type="checkbox" name="info01[]" value="체육관"> 체육관
</li>
<li>
<label for="info01" class="sound_only">골프장</label>
<input type="checkbox" name="info01[]" value="골프장"> 골프장
</li>
</ul>
</td>
</tr>
<tr>
<td class="head">특수 검색</td>
<td>
<ul>
<li>
<label for="info03" class="sound_only">계단식 공연장/강의장</label>
<input type="checkbox" name="info02[]" value="계단식 공연장/강의장"> 계단식 공연장/강의장
</li>
<li>
<label for="info03" class="sound_only">국제회의실</label>
<input type="checkbox" name="info02[]" value="국제회의실"> 국제회의실
</li>
<li style="color:#4ea6cb">
<label for="info03" class="sound_only">할인&특전</label>
<input type="checkbox" name="info02[]" value="할인/특전"> <b>할인 & 특전</b>
</li>
</ul>
</td>
</tr>
[/code]
[code]
$where = " and ";
$sql_search = "";
$ca_addr = $ca_10 = $in1 = $in2 = '';
if(trim($sido)) {
$stx2 = $sido.' '.$gugun;
$ca_addr = " and ca_addr1 like '%$stx2%' ";
}
if($gugun == '전체') {
$stx2 = $sido;
$ca_addr = " and ca_addr1 like '%$stx2%' ";
}
if(trim($pe_start) && trim($pe_end)) {
$ca_10 = " and ca_10 BETWEEN $pe_start AND $pe_end ";
}
else if(trim($pe_start)) {
$ca_10 = " and ca_10 BETWEEN 1 AND $pe_start ";
}
else if(trim($pe_end)) {
$ca_10 = " and ca_10 BETWEEN 1 AND $pe_end ";
}
$in1 = $in2 = '';
if(count($info01)) {
foreach($info01 as $value) {
$in1 .= " and ca_3 like '%$value%' ";
}
}
if(count($info02)) {
foreach($info02 as $value) {
$in2 .= " and ca_20 like '%$value%' ";
}
}
if ($stx != "") {
if ($sfl != "") {
$sql_search .= " $where $sfl like '%$stx%' $ca_addr $ca_10 $in1 $in2 ";
$where = " and ";
}
} else {
$sql_search .= " $ca_addr $ca_10 $in1 $in2 ";
}
[/code]