php 写的日历模板(未连接数据库)

<?php
$year = date('Y');
$month = date('n');
$day = date('j');
$firstDay = date("w", mktime(0,0,0,$month,1,$year));    // 周
$daysInMonth = date("t",mktime(0,0,0,$month,1,$year));
$tempDays = $firstDay + $daysInMonth;
$weeksInMonth = ceil($tempDays/7);
?>
<?php
        for($j=0;$j< $weeksInMonth;$j++) {
            for($i=0;$i<7;$i++) {
                @$counter++;
                $week[$j][$i] = $counter; 
                // offset the days
                $week[$j][$i] -= $firstDay;
                if (($week[$j][$i] < 1) || ($week[$j][$i] > $daysInMonth)) {    
                    $week[$j][$i] = "";
                }
            }
        }
include('functions/database.php');
get_connection();
?>
<script type="text/javascript" src="calendar.js"></script>
<table width="400" border="1" cellpadding="2" cellspacing="2">	
	<tr>		
		<th colspan='7'>
			<?php echo date('M', mktime(0,0,0,$month,1,$year)).' '.$year;?>
		</th>	
	</tr>
	<tr>		
		<th>Sun</th>		
		<th>Mon</th>		
		<th>Tue</th>		
		<th>Wed</th>		
		<th>Thur</th>		
		<th>Fri</th>		
		<th>Sat</th>	
		</tr>
<?php 
foreach ($week as $key => $val) { 	
	echo "<tr>";	
	for ($i=0;$i< 7;$i++) {
		//日期匹配
		echo "<td align='center'>".$val[$i]."</td>";
	}	
		echo "</tr>";}
?>
<tr id="calback">
	<th id="calendar" colspan='7'>
calendar
	</th>
</tr>
</table>

php 写的日历模板(未连接数据库)_第1张图片

你可能感兴趣的:(php 写的日历模板(未连接数据库))