php $문질문..

php $문질문..

QA

php $문질문..

본문

주문내역을 검색하는기능을 탐색하는 와중에 오류가 생겼는데요..

 

if( !isset($fr_date) && !isset($to_date) ){

    $sel_field = 'od_time';

    $fr_date = date("Y-m-d", strtotime("-14 day"));

    $to_date = TB_TIME_YMD;

    $qstr .= "&sel_field=$sel_field&fr_date=$fr_date&to_date=$to_date";

}

현재이구문으로 od_time(주문 일시 db 데이터) 를 받아오고 

<?php echo get_search_date("fr_date", "to_date", $fr_date, $to_date); ?>

로  가져올 월 일 이랑 버튼으로 하루 일주일 일개월 삼개월 순으로 검색할 수 있는 버튼이만들어지는데 아무리봐도 이버튼을 만드는 코드를 모르겠어요..ㅠ  위구문을 지워봐서 안나온걸봐선 위구문인거같은데 도대체 어디서만들어진걸지 감이안온다고해야하나..

 $("#fr_date, #to_date").datepicker({ changeMonth: true, changeYear: true, dateFormat: "yy-mm-dd", showButtonPanel: true, yearRange: "c-99:c+99", maxDate: "+0d" }); 이건 스크립트 코드입니다. 981215425_1632878172.1298.png

혹시몰라 이미지 올립니다. 저기 오늘 어제 일주일 저버튼을 6개월 12개월 이런식으로 늘려버리고 싶거든요 혹시 다른코드나 참고할꺼 필요하시면 말씀부탁드립니다

이 질문에 댓글 쓰기 :

답변 3

기존 코드 분석이 어려우면 사실 수정이 어렵다고 보여집니다

부디 좋은 결과 있으시길 바라겠습니다

내용이 길어지는데 순서대로 적어드릴께요 .

우선 하시고 싶은건 위에 이미지를 6개월,12개월 이런식으로 늘리고 싶다는 얘기시죠 ?

 

orderlist.php 를 보시면

위에 오늘,어제 부분의 소스를 보시면 됩니다


<div class="sch_last">
    <strong>주문일자</strong>
    <input type="text" id="fr_date"  name="fr_date" value="<?php echo $fr_date; ?>" class="frm_input" size="10" maxlength="10"> ~
    <input type="text" id="to_date"  name="to_date" value="<?php echo $to_date; ?>" class="frm_input" size="10" maxlength="10">
    <button type="button" onclick="javascript:set_date('오늘');">오늘</button>
    <button type="button" onclick="javascript:set_date('어제');">어제</button>
    <button type="button" onclick="javascript:set_date('이번주');">이번주</button>
    <button type="button" onclick="javascript:set_date('이번달');">이번달</button>
    <button type="button" onclick="javascript:set_date('지난주');">지난주</button>
    <button type="button" onclick="javascript:set_date('지난달');">지난달</button>
    <button type="button" onclick="javascript:set_date('전체');">전체</button>
    <input type="submit" value="검색" class="btn_submit">
</div>

이렇게 되어있으실텐데요 

여기 보시면 지난 달의 경우 set_date('지난달'); 로 set_date 함수를 호춯합니다

 

같은 페이지에 set_date 함수를 보시면



function set_date(today)
{
    <?php
    $date_term = date('w', G5_SERVER_TIME);
    $week_term = $date_term + 7;
    $last_term = strtotime(date('Y-m-01', G5_SERVER_TIME));
    ?>
    if (today == "오늘") {
        document.getElementById("fr_date").value = "<?php echo G5_TIME_YMD; ?>";
        document.getElementById("to_date").value = "<?php echo G5_TIME_YMD; ?>";
    } else if (today == "어제") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
    } else if (today == "이번주") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$date_term.' days', G5_SERVER_TIME)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
    } else if (today == "이번달") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', G5_SERVER_TIME); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
    } else if (today == "지난주") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$week_term.' days', G5_SERVER_TIME)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', strtotime('-'.($week_term - 6).' days', G5_SERVER_TIME)); ?>";
    } else if (today == "지난달") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', strtotime('-1 Month', $last_term)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-t', strtotime('-1 Month', $last_term)); ?>";
    } else if (today == "전체") {
        document.getElementById("fr_date").value = "";
        document.getElementById("to_date").value = "";
    }
}

 

이렇게 되어있으신데요

여기도 보시면 지난달 일때 

        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', strtotime('-1 Month', $last_term)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-t', strtotime('-1 Month', $last_term)); ?>";

 

이런식으로 값을 넣어줍니다

이걸 응용해서 수정하시면 됩니다

 

6개월을 추가할때

검색 부분에


<div class="sch_last">
    <strong>주문일자</strong>
    <input type="text" id="fr_date"  name="fr_date" value="<?php echo $fr_date; ?>" class="frm_input" size="10" maxlength="10"> ~
    <input type="text" id="to_date"  name="to_date" value="<?php echo $to_date; ?>" class="frm_input" size="10" maxlength="10">
    <button type="button" onclick="javascript:set_date('오늘');">오늘</button>
    <button type="button" onclick="javascript:set_date('어제');">어제</button>
    <button type="button" onclick="javascript:set_date('이번주');">이번주</button>
    <button type="button" onclick="javascript:set_date('이번달');">이번달</button>
    <button type="button" onclick="javascript:set_date('지난주');">지난주</button>
    <button type="button" onclick="javascript:set_date('지난달');">지난달</button>
    <button type="button" onclick="javascript:set_date('6개월');">6개월전</button>
    <button type="button" onclick="javascript:set_date('전체');">전체</button>
    <input type="submit" value="검색" class="btn_submit">
</div>

 

로 6개월을 추가하시고

set_date 함수에


function set_date(today)
{
    <?php
    $date_term = date('w', G5_SERVER_TIME);
    $week_term = $date_term + 7;
    $last_term = strtotime(date('Y-m-01', G5_SERVER_TIME));
    ?>
    if (today == "오늘") {
        document.getElementById("fr_date").value = "<?php echo G5_TIME_YMD; ?>";
        document.getElementById("to_date").value = "<?php echo G5_TIME_YMD; ?>";
    } else if (today == "어제") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME - 86400); ?>";
    } else if (today == "이번주") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$date_term.' days', G5_SERVER_TIME)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
    } else if (today == "이번달") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', G5_SERVER_TIME); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', G5_SERVER_TIME); ?>";
    } else if (today == "지난주") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-d', strtotime('-'.$week_term.' days', G5_SERVER_TIME)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-d', strtotime('-'.($week_term - 6).' days', G5_SERVER_TIME)); ?>";
    } else if (today == "지난달") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', strtotime('-1 Month', $last_term)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-t', strtotime('-1 Month', $last_term)); ?>";
    } else if (today == "6개월") {
        document.getElementById("fr_date").value = "<?php echo date('Y-m-01', strtotime('-6 Month', $last_term)); ?>";
        document.getElementById("to_date").value = "<?php echo date('Y-m-t', strtotime('-6 Month', $last_term)); ?>";
    } else if (today == "전체") {
        document.getElementById("fr_date").value = "";
        document.getElementById("to_date").value = "";
    }
}

 

이런식으로 6개월전 날짜를 구해주는 부분을 추가하시면 됩니다

너무자세한답변 감사합니다.. 근데 제가 관리하는 쇼핑몰이 영카트기반으로만만들어져서 영카트랑은 구조가좀달라요..ㅠ orderlist.php 파일도없을 뿐더러 order_list.php나 order 폴더에있는 모든파일을 뒤져봐도 오늘 내일 1개월 이런식의 input 타입형태가 없습니다. ㅠㅠ fr_date to_date관련함수는 제가올린게 전부에요 ㅠㅠ..

그 페이지에서 코드 크롤링 해서 왓을땐

<span class="btn_group"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="오늘"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="어제"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="일주일"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="지난달"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="이번달"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="1개월"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="3개월"><input type="button" onclick="search_date('fr_date','to_date',this.value);" class="btn_small white" value="전체"></span> 이런식으로보여지긴합니다..

저위 코드는 상관없습니다

 

구현 방식을 보시고 응용하셔야 합니다

 

포인트는

 

. 기존 지난달,이번달의 액션이 어떻게 처리되는지 확인

. 기존 코드에 원하는 코드 추가

. 해당 기능에 맞는 날짜 계산 추가

 

의 형태로 하시면 됩니다

사실 기존 코드의 액션이 진행되고있는 부분을 찾으면 저혼자서도 해결할 수 있을거같은데.. 도저히 찾아도 저 코드들이 어디서 작동하고 있는지 찾을 수가 없어요..ㅠ... 친절한답변너무 감사드립니다..

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

회원로그인

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