날짜 검색 관련 질문입니다!

날짜 검색 관련 질문입니다!

QA

날짜 검색 관련 질문입니다!

본문

안녕하세요! 저번에도 이것과 관련해서 질문을 남겼는데 제대로 해결이 되지 않아 다시 질문을 올리게 되었습니다! 정말 죄송합니다 ㅠㅠㅠ

지금 다른 분들이 올려놓은 것들은 참고하면서 수정을 하고 있는데

날짜를 검색했을 때

theme>basic>skin>board>basic>list.skin.php 에서


    <!-- 게시판 검색 시작 { -->
    <div class="bo_sch_wrap">
        <fieldset class="bo_sch">
            <h3>검색</h3>
            <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">
            <label for="sfl" class="sound_only">검색대상</label>
            <!-- 날짜 검색 시작 { -->
            <!-- } 날짜검색 끝 -->  
            <label for="stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
            <div class="sch_bar">
                <input type="hidden" name="sfl" value="wr_1_start"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
                ~
                <input type="hidden" name="sfl" value="wr_1_end"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx2" 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>
            </div>
            <button type="button" class="bo_sch_cls" title="닫기"><i class="fa fa-times" aria-hidden="true"></i><span class="sound_only">닫기</span></button>
            </form>
        </fieldset>
        <div class="bo_sch_bg"></div>
    </div>

 

여기서 이렇게 input을 넣고 그 값 사이의 값들을 받고

 

bbs>list.php에서

 


if ($sca || $stx || $stx === '0') {     //검색이면
    $is_search_bbs = true;      //검색구분변수 true 지정
    if($bo_table == "purchase_drug")//약품구매게시판인경우
    $sql_search="{$sfl} between '{$wr_1_start}' and '{$wr_1_end}'";
    else
    $sql_search = get_sql_search($sca, $sfl, $stx, $sop);
 
    // 가장 작은 번호를 얻어서 변수에 저장 (하단의 페이징에서 사용)
    $sql = " select MIN(wr_num) as min_wr_num from {$write_table} ";
    $row = sql_fetch($sql);
    $min_spt = (int)$row['min_wr_num'];

 

이렇게 if else로 나누어 게시판 테이블명이 동일했을 때 관련 리스트가 출련된다고 저는 이해를 했는데 도저히 값이 나오지 않아 다시 질문하게 되었습니다. 

 

mysql에서 나오는 쿼리문만 입력하면 바로 나올 것 같은데 이것들을 어디서 입력해야할지도 정말 막막합니다!ㅠㅠㅠ

 

3537816078_1623224036.0543.png

너무 초보라 아직 개념이 많이 부족하지만 열심히 하고 있습니다!! 귀한 시간을 내어 알려주셔서 항상 감사합니다!!

 

이 질문에 댓글 쓰기 :

답변 3

    <div class="bo_sch_wrap">
        <fieldset class="bo_sch">
            <h3>검색</h3>
            <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" />
            <label for="sfl" class="sound_only">검색대상</label>
            <!-- 날짜 검색 시작 { -->
            <!-- } 날짜검색 끝 -->  
            <label for="stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
            <div class="sch_bar">
                <input type="hidden" name="sfl" value="wr_1_start"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <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="날짜검색">
                ~
                <input type="hidden" name="sfl2" value="wr_1_end"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <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="날짜검색">
            <button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span>
            </div>
            <button type="button" class="bo_sch_cls" title="닫기"><i class="fa fa-times" aria-hidden="true"></i><span class="sound_only">닫기</span></button>
            </form>
        </fieldset>
        <div class="bo_sch_bg"></div>
    </div>

 

 

그리고 다음 함수에서 굵은 부분 추가

 

 

 

"/lib/common.lib.php" 

function get_sql_search($search_ca_name, $search_field, $search_text, $search_operator='and'){

global $g4, $stx2;

...

            switch ($field[$k]) {

                case "wr_12" :

                    $str .= " wr_1 between '$stx' and '$stx2' ";

                    break;
                case "mb_id" :
                case "wr_name" :
                    $str .= " $field[$k] = '$s[$i]' ";
                    break;

 

소중한 시간 내어 주셔서 정말 감사합니다!! 지금 알려주신대로 입력했습니다! 그런데 기간선택중에 마지막 기간은 인식을 하는데 처음 시작 기간을 인식하지 못해서 처음부터 두번째 기간 선택 날까지 화면에 표출됩니다!ㅠㅠ

일단 저기 밑에다가

print_r($_GET);

exit();

 

찍고 실행한다음 값을 비교해보세요

아마 sfl 이 배열로 넘어간다거나 원하는 값이 아닐거입니다.

 

하나씩 찍어보면서 수정하면될거에여

GET 변수를 어떻게 전달할 지, 전달받은 GET 변수로 쿼리문을 어떻게 만들지에 대한 개념을 먼저 정리해보는 것이 도움이 될 수 있습니다.

 

&sfl=wr_1&stx=2021-05-25&stx2=2021-08-10

 

=>

 

$sql = " ~ where {$sfl} between {$stx} and {$stx2} ";

 

형태가 될 것입니다.

 

이렇게 하기 위해 수정해야할 부분을 정리하면 다음과 같습니다.


           <div class="sch_bar">
                <input type="hidden" name="sfl" value="wr_1_start"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
                ~
                <input type="hidden" name="sfl" value="wr_1_end"<?php echo get_selected($sfl, 'wr_1'); ?>>
                <i class="fa fa-calendar" aria-hidden="true"></i> <input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" required id="stx2" class="sch_input" size="25" maxlength="20" placeholder="날짜검색">
            <button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true">

=>


           <div class="sch_bar">
                <input type="hidden" name="sfl" value="wr_1">
                <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="날짜검색">
            <button type="submit" value="검색" class="sch_btn"><i class="fa fa-search" aria-hidden="true">

 


    if($bo_table == "purchase_drug")//약품구매게시판인경우
    $sql_search="{$sfl} between '{$wr_1_start}' and '{$wr_1_end}'";
    else
    $sql_search = get_sql_search($sca, $sfl, $stx, $sop);
[code]

=>


    if ($bo_table == "purchase_drug" && $sfl == 'wr_1')//약품구매게시판인경우
      $sql_search= " {$sfl} between '{$stx}' and '{$stx2}' ";
    else
      $sql_search = get_sql_search($sca, $sfl, $stx, $sop);

if ($bo_table == "purchase_drug" && $sfl == 'wr_1')//약품구매게시판인경우
      $sql_search= " {$sfl} between '{$stx}' and '{$stx2}' ";
    else
      $sql_search = get_sql_search($sca, $sfl, $stx, $sop);

echo $sql_search;
exit;

로 sql문 등을 확인해가며 디버깅해볼 수 있습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 123,666 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT