참 이상하네요..
본문
엑셀로 다운받는데...
wr_datetime기준으로 받는거 같은데..
9월달 출력하니..
wr_datetime가 7월인게 한개 끼어있네요,,
그래서 디비에 보니 wr_last이게 9월로 기록되어 있네요,,
wr_datetime기준으로 다운받는데..이렇게 될 수가 있나요?
너무 단조로우니 7월거도 끼워주는겅가요?
코드은 아래와 같습니다..
$where = array();
if($sca || $stx){
$where[] = 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 = $row[min_wr_num];
if (!$spt) $spt = $min_spt;
$where[] = " (wr_num between '".$spt."' and '".($spt + $config[cf_search_part])."') ";
}
if($t_start || $t_end){
if($t_start){
$t_start=preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $t_start);
$where[] = " wr_datetime >= '$t_start' ";
$qstr.="&t_start=$t_start";
}
if($t_end){
$t_end =preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $t_end);
if($t_start) $sql_period.=" and ";
$where[] = "wr_datetime <= '$t_end' ";
$qstr.="&t_end=$t_end";
}
}
if(count($where) > 0){
$sql_order = ' order by wr_datetime';
$sql_search .= implode(' AND ', $where);
$sql = " select distinct wr_parent from $write_table where $sql_search $sql_order";
} else {
$sql_order = " order by wr_num, wr_reply ";
$sql = " select * from $write_table where wr_is_comment = 0 $sql_order ";
}
/*echo $sql;
exit;*/
$result = sql_query($sql);
$cnt = sql_num_rows($result);
if (!$cnt)
alert("출력할 내역이 없습니다.");
header('Content-Type: application/vnd.ms-excel');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="list' . date("ymd", time()) . '.xls"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('content-transfer-encoding: binary');
echo "<html><head>";
echo "<meta http-equiv='Content-Type' content='application/vnd.ms-excel;charset=utf-8'>";
echo "</head><body>";
답변 2
if($t_start || $t_end){
if($t_start){
$t_start=preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $t_start);
$where[] = " wr_datetime >= '$t_start' ";
$qstr.="&t_start=$t_start";
}
if($t_end){
$t_end =preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $t_end);
if($t_start) $sql_period.=" and ";
$where[] = "wr_datetime <= '$t_end' ";
$qstr.="&t_end=$t_end";
}
}
로직상으로는 문제가 없어 보입니다.
t_start 가 2017-09-01
t_end 가 2017-09-30 이라면
wr_datetime 기준으로 2017년 9월 데이터만 나와야 정상입니다.
(wr_last 값에 영향받을 수는 없습니다.)
만약 원하는대로 나오지 않는다고 하면,
1) t_start, t_end 값이 제대로 설정되었는지를 점검
2) sql 구문이 맞게 적용되었는지 점검
(echo $sql 로 where wr_datetime >= '2017-09-01' and wr_datetime <= '2017-09-30' 식으로 되어있는지..)
해볼 수 있을 듯 합니다.
sql 구문을 보여주시면 더 빠르겠네요 ^^