select박스 날짜 DB연동 질문

select박스 날짜 DB연동 질문

QA

select박스 날짜 DB연동 질문

본문

3718050134_1644313511.8828.png

 

현재  이미지 아랫부분에 월간매출의 input박스를 셀렉트 박스를 이용해서 

 

3718050134_1644313533.2292.png

 

기간을 정해놔서 DB를 불러오게 하려고 하는데

db를 어떻게 해야될지 모르겟습니다

 



$sql = "SELECT  SUM(ct_price) as total_pay,
        SUBSTRING(ct_time,1,7) as ctDt,
        SUM(IF(at_status, 0, ct_price)) as x_pay,
        SUM(at_price) as already_pay,
        COUNT(*)  as cnt
        FROM `g5_shop_cart`  cart JOIN  g5_shop_item itm  ON cart.it_id  = itm.it_id
        WHERE itm.it_2_subj ='{$member["mb_id"]}' AND  at_status=0";


if ($_GET["fr_month"]) {
    $fr_date = $_GET["fr_month"];
    $to_date = $_GET["to_month"];
    $sql.= " AND  SUBSTRING(ct_time,1,7) between '$fr_date' AND '$to_date' ";
    $qstr = "fr_date=$fr_date&to_date=$to_date";
}

$result = sql_query($sql, true);
?>

<?php print_r($sql) ?>


<div>
    <form name="frm_month" action="" method="get">
        <strong>기간</strong>
        <select name="fr_month">
            <option>2022년</option>
        </select>
        <select name="month">
            <?php for($i=1; $i<=12; $i++){ ?>
           <option><?= $i?>월</option>";
           <? }
            ?>
        </select>

    </form>



</div>
<div>
    <form name="frm_sale_month" action="" method="get">
        <strong>월간 매출</strong>
        <input type="text" name="fr_month" value="<?php echo date("Y01", G5_SERVER_TIME); ?>" id="fr_month" required
               class="required frm_input" size="6" maxlength="6">
        <label for="fr_month">월 ~</label>
        <input type="text" name="to_month" value="<?php echo date("Ym", G5_SERVER_TIME); ?>" id="to_month" required
               class="required frm_input" size="6" maxlength="6">
        <label for="to_month">월</label>
        <input type="submit" value="확인" class="btn_submit">
    </form>
</div>
<div class="tbl_head01 tbl_wrap">


 

 

1.option value 값을 date("Y01", G5_SERVER_TIME)를 사용해야되는데 년 값과 월 값을 어떻게 가져와야되는지

 

 

 

2.  $fr_date = $_GET["fr_month"]; $to_date = $_GET["to_month"]; 

////////////////////////////////

AND SUBSTRING(ct_time,1,7) between '$fr_date' AND '$to_date' ";

의 between 을 수정해야될것같은데 어떻게 수정을 해야되는지 여쭙고 싶습니다

 

이 질문에 댓글 쓰기 :

답변 1



$sql = "SELECT  SUM(ct_price) as total_pay,
        SUBSTRING(ct_time,1,7) as ctDt,
        SUM(IF(at_status, 0, ct_price)) as x_pay,
        SUM(at_price) as already_pay,
        COUNT(*)  as cnt
        FROM `g5_shop_cart`  cart JOIN  g5_shop_item itm  ON cart.it_id  = itm.it_id
        WHERE itm.it_2_subj ='{$member["mb_id"]}' AND  at_status=0";

if ($_GET["s_year"] != "" && $_GET["s_month"]) {
    $s_date = $_GET["s_year"]."-".$_GET["s_month"];
    $sql.= " AND  SUBSTRING(ct_time,1,7) = '$s_date' ";
    $qstr = "s_year=$s_year&s_month=$s_month";
}
$result = sql_query($sql, true);
?>
<?php print_r($sql) ?>

<div>
    <form name="frm_month" action="" method="get">
        <strong>기간</strong>
        <select name="s_year" onChange="this.form.submir();">
            <option value="2022">2022년</option>
        </select>
        <select name="s_month" onChange="this.form.submir();">
            <?php for($i=1; $i<=12; $i++){ ?>
           <option value="<?=$i?>"><?= $i?>월</option>";
           <? }
            ?>
        </select>
    </form>
</div>
 
답변을 작성하시기 전에 로그인 해주세요.
전체 62
QA 내용 검색

회원로그인

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