【发布时间】:2015-01-15 14:30:58
【问题描述】:
我是编程初学者,我必须为我的学校项目建立一个网站。 在一些帮助下,我终于建立了一个日历:耶! 但现在我必须浏览我的日历:浏览月份和年份。 例如,今天是 2015 年 1 月 15 日,我想转到 2016 年,或者到 1 月 26 日。我真的不知道该怎么做......:( 有人可以帮我吗?我会很感激的:) 我的日历代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
setlocale(LC_ALL, 'nl_NL');
$today_date = time();
$day = date('d', $today_date);
$month = date('m', $today_date);
$year = date('Y', $today_date);
// Make first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
// Get name of the month
$title = date('F', $first_day);
// What day of the week is the first day of the month
$day_of_week = date('D', $first_day);
// Lege plekken invullen
switch($day_of_week) { case "Sat": $blank = 6; break;
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
}
// hoeveel dagen in een maand
$days_in_month = cal_days_in_month(0, $month, $year);
// Bovenkant
echo '<table border="0" cellspacing="0" cellpadding="0" width="1500px"> ';
echo '<tr><th colspan="7" class = "monthname"> ' .$title . ' ' . $year. ' </th></tr>';
echo '<tr> <td width="50" class="weekend">Zondag</td>
<td width="50" class = "dag">Maandag</td>
<td width="50" class = "dag">Dinsdag</td>
<td width="50" class = "dag">Woensdag</td>
<td width="50" class = "dag">Donderdag</td>
<td width="50" class = "dag">Vrijdag</td>
<td width="50" class="weekend">Zaterdag</td>
</tr>';
$day_count = 1;
echo '<tr>';
// De dagen die er in een maand niet zijn invullen met een leeg vak
while ( $blank > 0 ) {
if ($day_count == 1 || $day_count == 7) {
echo '<td class="weekend"> </td>';
} else
{echo '<td></td>'; }
$blank = $blank - 1;
$day_count++;
}
$day_num = 1;
while ($day_num <= $days_in_month) { if ($day_count == 1 || $day_count == 7) { if ($day_num == $day) { echo ' <td class="weekend today">
<a href="./dag=' .$day_num. '&maand=' .$month. '"> ' .$day_num. ' </a>
</td>'; } else { echo '
<td class="weekend">
<a href="./dag=' .$day_num. '&maand=' .$month. '"> ' .$day_num. ' </a>
</td>'; } } else { if ($day_num == $day) { echo '
<td class="today">
<a href="./dag=' .$day_num. '&maand=' .$month. '"> ' .$day_num. ' </a>
</td>'; } else { echo '
<td>
<a href="./dag=' .$day_num. '&maand=' .$month. '"> ' .$day_num. ' </a>
</td>'; } } $day_num++; $day_count++;
// Seperate the week out onto new lines
if ($day_count > 7) { echo '</tr>
<tr>
'; $day_count = 1; } }
// Blank out days not needed at the end of the month
while ($day_count > 1 && $day_count <= 7) { if ($day_count == 1 || $day_count == 7) { echo '<td class="weekend">
</td>'; } else
{ echo '<td>
</td>'; } $day_count++; }
// End the table
echo '</tr></table>';
?>
</div>
</body>
</html>
【问题讨论】:
-
从创建
$today_date变量开始,例如$today_date = isset($_GET['timestamp']) ? intval($_GET['timestamp']) : time();,这样您就可以根据网址请求不同的日历。然后添加适当的链接,在该数字中添加和减去天/月/年(以秒为单位...)。 -
我想浏览我的日历,我的意思是添加一个按钮“明年”,转到 2016 年。还有一个按钮“下个月”,转到 2 月而不是 1 月。我真的不知道该怎么做..
标签: php html calendar controls