게시판 검색 기능 관련 질문드립니다! 채택완료
검색 기능을 하는데 날짜와 약품명을 입력하면 해당되는 날짜와 약품명이 해당되는 리스트를 표출을 하게 하려고 하는데 입력을 하면 게시물이 없다고만 뜹니다 ㅠㅠㅠㅠㅠ
</strong></p>
<p><form name="fsearch" method="get"></p>
<p> <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>"></p>
<p> <input type="hidden" name="sca" value="<?php echo $sca ?>"></p>
<p> <input type="hidden" name="sop" value="and"></p>
<p> <input type="hidden" name="sfl" value="wr_12" /></p>
<p> <tr><input type="hidden" name="sfl" value="wr_1"<?php echo get_selected($sfl, 'wr_1'); ?>>구매일자</input></p>
<p> <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx" class="sch_input" size="25" maxlength="20" placeholder="날짜검색"></p>
<p> ~</p>
<p> <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx2" value="<?php echo stripslashes($stx2) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색"></p>
<p> </p>
<p> <input type="hidden" name="sfl" value="wr_subject"<?php echo get_selected($sfl, 'wr_subject'); ?>>약품명</input></p>
<p> <label for="stx3" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label> </p>
<p> <input type="text" name="stx3" value="<?php echo stripslashes($stx3) ?>" required id="stx3" class="sch_input" size="25" maxlength="20" placeholder=" 검색어를 입력해주세요"> </p>
<p> <button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span></button></p>
<p> </tr></p>
<p> </form></p>
<p><strong>

이렇게 입력하고 검색하면 보이는 게시물이 검색이 되야 하는데

이렇게 나오네요 ㅠㅠㅠㅠㅠ 어떻게 해결 해야 할까요??
답변 4개
1. common.lib.php에 있는 function get_sql_search() 함수를 이용할지 아니면
2. list.php에서 조건부로 $sql_search를 만들어 쓸지 정해야 합니다.
2번을 쓴다면
$is_search_bbs = false;
if ($sca || $stx || $stx === '0') { //검색이면
$is_search_bbs = true; //검색구분변수 true 지정
if($bo_table == "purchase_stock")
$sql_search="{$sfl} between '{$stx}' and '{$stx2}'";
else
$sql_search = get_sql_search($sca, $sfl, $stx, $sop);
이 부분을 수정하시면 됩니다.
<form name="fsearch" method="get">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sop" value="and">
<input type="hidden" name="sfl" value="wr_12" />
<tr><input type="hidden" name="sfl" value="wr_1"<?php echo get_selected($sfl, 'wr_1'); ?>>구매일자</input>
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
~
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx2" value="<?php echo stripslashes($stx2) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
<input type="hidden" name="sfl" value="wr_subject"<?php echo get_selected($sfl, 'wr_subject'); ?>>약품명</input>
<label for="stx3" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx3" value="<?php echo stripslashes($stx3) ?>" required id="stx3" class="sch_input" size="25" maxlength="20" placeholder=" 검색어를 입력해주세요">
<button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span></button>
</tr>
</form>
list.php에서
if ($sca || $stx || $stx === '0') { //검색이면
$is_search_bbs = true; //검색구분변수 true 지정
if($bo_table == "purchase_stock") {
$sql_search=" wr_날짜들어간여분컬럼번호 between '{$stx1}' and '{$stx2}' and wr_약품명컬럼 like '%{$stx3}%' ";
}else $sql_search = get_sql_search($sca, $sfl, $stx, $sop);
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 3개
[code]
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>
<script>
$.datepicker.setDefaults({
dateFormat: 'yy-mm',
prevText: '이전 달',
nextText: '다음 달',
monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
dayNames: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesShort: ['일', '월', '화', '수', '목', '금', '토'],
dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
showMonthAfterYear: true,
yearSuffix: '년'
});
$(function() {
$("#stx, #stx2, #e_Date").datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
<div style="width:<?php echo $width; ?>; text-align:left;">
<!-- 날짜 검색 시작 { -->
<form name="fsearch" method="get">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sop" value="and">
<input type="hidden" name="sfl" value="wr_12" />
<tr><input type="hidden" name="sfl" value="wr_1"<?php echo get_selected($sfl, 'wr_1'); ?>>구매일자</input>
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
~
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx2" value="<?php echo stripslashes($stx2) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
<input type="hidden" name="sfl" value="wr_subject"<?php echo get_selected($sfl, 'wr_subject'); ?>>약품명</input>
<label for="stx3" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx3" value="<?php echo stripslashes($stx3) ?>" required id="stx3" class="sch_input" size="25" maxlength="20" placeholder=" 검색어를 입력해주세요">
<button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span></button>
</tr>
</form>
</div>[/code]
common.lib.php
[code]
$str .= $op2;
switch ($field[$k]) {
case "wr_12" :
$str .= " wr_1 between '{$s[$i]}' and '$stx2' ";
break;
case "mb_id" :
case "wr_name" :
$str .= " $field[$k] = '$s[$i]' ";
break;
[/code]
list.php
[code]
$is_search_bbs = false;
if ($sca || $stx || $stx === '0') { //검색이면
$is_search_bbs = true; //검색구분변수 true 지정
if($bo_table == "purchase_stock")
$sql_search="{$sfl} between '{$stx}' and '{$stx2}'";
else
$sql_search = get_sql_search($sca, $sfl, $stx, $sop);
// 가장 작은 번호를 얻어서 변수에 저장 (하단의 페이징에서 사용)
[/code]
소스코드는 이렇습니다! list.skin.php에서
<input type="hidden" name="stx" value="<?php echo $stx ?>">
<input type="hidden" name="stx2" value="<?php echo $stx2 = $_GET['stx2'] ? $_GET['stx2'] : ''; ?>">
이렇게 수정한 부분도 있습니다!
말씀드린 것부터 하나씩 수정해 보세요.
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sop" value="and">
<input type="hidden" name="sfl2" value="wr_1"<?php echo get_selected($sfl2, 'wr_1'); ?>>구매일자</input>
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="date" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
~
<i class="fa fa-calendar" aria-hidden="true"></i> <input type="date" name="stx2" value="<?php echo stripslashes($stx2) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
<input type="hidden" name="sfl" value="wr_subject"<?php echo get_selected($sfl, 'wr_subject'); ?>>약품명</input>
<label for="stx3" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx3" value="<?php echo stripslashes($stx3) ?>" required id="stx3" class="sch_input" size="25" maxlength="20" placeholder=" 검색어를 입력해주세요">
<button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span></button>
</tr>
</form>[/code]
이렇게 하시라는 말씀이 맞나요???
댓글을 작성하려면 로그인이 필요합니다.
sfl 은 검색필드를 의미하고 stx는 검색어를 의미합니다.
예를 들어 게시판에서 제목과 내용을 검색할때
sfl = wr_subject||wr_content
stx = 검색어
와 같은 형태로 되어 있습니다.
위 내용대로라면 sfl 은 wr_subject 가 되고, stx 는 첫번째 날짜검색 필드이 값이 되겠네요.
이 부분을 이해하셔서 코드를 다시 짜셔야 하지만,
코어를 건드리거나, 별도의 자바스크립트를 통해 sfl 을 새로 구성을 해주셔야 합니다.
하지만 날짜 검색 같은 경우는 코어를 수정하셔야 할 듯 합니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인