PHP日历 - 与当月相比任何其他月份都有问题

时间:2010-09-29 03:55:46

标签: php calendar

我正在构建我的第一个需要日历的应用程序。我觉得这个月工作得很好。我的问题是,我不知道如何制作它,以便当用户点击链接转到下个月时,它将显示下个月。

我会尝试只发布必要的代码,所以这是我的变量

//gets todays date
$date = time();

//This puts the day, month, and year in separate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('y', $date);
$bigYear = date('Y', $date);
$first_day = mktime(0, 0, 0, $month, 1, $year);             //we need to generate the first day of the month
$month_name = date('F', $first_day);                        //get the current month's full spelling
$day_of_week = date('D', $first_day);                       //find out what day of the week the first day of the month falls on
$prevM = getDate(mktime(0, 0, 0, $month-1, 1, $year));      //gets an associative array of the previous month
$nextM = getDate(mktime(0, 0, 0, $month+1, 1, $year));      //gets an associative array of the next month
$prevMonth = $prevM['month'];                               //gets the actual previous month's name
$nextMonth = $nextM['month'];                               //gets the actual next month's name
$day_count = 1;                                             //counts the days up to 7 so we know when to start a new week
$day_num = 1;                                               //counter for the total number of days in the month

这是我的链接,可以带你到下一个月和前几个月

echo "<th colspan=2 class=\"noBorder\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevMonth'>&laquo;</a></th>";
echo "<th colspan=3 class=\"noBorder\"><strong>$month_name</strong></th>";
echo "<th colspan=2 class=\"noBorder\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextMonth'>&raquo;</a></th>";

2 个答案:

答案 0 :(得分:1)

类似的东西:

$date = empty($_GET['currentpage']) ? time() : $_GET['currentpage'];

答案 1 :(得分:1)

试试这个:

$date = empty($_GET['currentpage']) ? time() : strtotime($_GET['currentpage']);

$prevMonth = "{$prevM['year']}-{$prevM['mon']}";
$nextMonth = "{$nextM['year']}-{$nextM['mon']}";