select박스 날짜 DB연동 질문
본문
현재 이미지 아랫부분에 월간매출의 input박스를 셀렉트 박스를 이용해서
기간을 정해놔서 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>
답변을 작성하시기 전에 로그인 해주세요.