PHP 日历 - 除当前月份之外的任何其他月份的问题
我正在构建第一个需要日历的应用程序。我这个月工作得很好。我的问题是我不知道如何做到这一点,以便当用户单击链接转到下个月时,它将显示下个月。
我将尝试仅发布必要的代码,因此这是我的变量
//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'>«</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'>»</a></th>";
I'm building my first application that requires a calendar. I have it working great for the current month. My problem is that i'm not sure how to make it so that when a user clicks the link to go to the next month, it will show the next month.
I'll try to only post the code that is necessary so here's my variables
//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
and here's my links that are supposed to take you to the next and previous months
echo "<th colspan=2 class=\"noBorder\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevMonth'>«</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'>»</a></th>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
并且:
Try this:
And:
像这样的东西:
Something like: