날짜 선택
PHP에서 날짜 선택을 깔끔하게 하는 코드를 적어둔다.
<?php
//---- 오늘 날짜
$thisyear = date("Y");
$thismonth = date("m");
$today = date("d"); // 1, 2, 3, ..., 31
//------ $year, $month 값이 없으면 현재 날짜
$year = isset($_GET['year']) ? $_GET['year'] : $thisyear;
$month = isset($_GET['month']) ? $_GET['month'] : $thismonth;
$day = isset($_GET['day']) ? $_GET['day'] : $today;
$start_date = date("Y", mktime(0, 0, 0, date("m"), date("d"), date("Y") - 1));
$end_date = date("Y", mktime(0, 0, 0, date("m"), date("d"), date("Y") + 3));
?>
<TR>
<TD >시작날짜</TD>
<TD colspan="2" rowspan="1">
<select name="start_date1">
<?php for($i=$start_date;$i<$end_date;$i++):?><option value="<?php echo $i?>"<?php if($year==$i):?> selected="selected"<?php endif?>><?php echo $i?>년</option><?php endfor?>
</select>
<select name="start_date2" >
<?php for($i=1;$i<13;$i++):?><option value="<?php echo sprintf('%02d',$i)?>"<?php if($month==$i):?> selected="selected"<?php endif?>><?php echo sprintf('%02d',$i)?>월</option><?php endfor?>
</select>
<select name="start_date3" >
<?php for($i=1;$i<32;$i++):?><option value="<?php echo sprintf('%02d',$i)?>"<?php if($day==$i):?> selected="selected"<?php endif?>><?php echo sprintf('%02d',$i)?>일</option><?php endfor?>
</select>
</TD>
</TR>