반응형

<?php
function calender($year, $month) {
$startWeek = date('w', mktime(0, 0, 0, $month, 1, $year));
$dayRows = date('t', mktime(0, 0, 0, $month, 1, $year));
?>
<table border="0" cellpadding="0" cellspacing="0" class="table_2">
    <tr>
        <th>일요일</th>
        <th>월요일</th>
        <th>화요일</th>
        <th>수요일</th>
        <th>목요일</th>
        <th>금요일</th>
        <th>토요일</th>
    </tr>
    <?php
    for ($i = 1; $i <= 42; $i++) {
        $varDay = $i - $startWeek;
        if ($i%7 == 1)  echo '<tr>';
        if ($varDay > 0 && $varDay <= $dayRows )
            echo '<td>'.$varDay.'</td>';
        else
            echo '<td> </td>';
        if ($i%7 == 0)  echo '<tr>';
    }
    ?>
</table>
<?php
}
?>

PS
1일의 요일값과, 해당 월의 총 일수를 한 번에…. ^^);
list($startWeek,$dayRows) = explode(' ',date('w t',mktime(0,0,0,$month,1,$year)));
반응형

+ Recent posts