PHP 日历 - 除当前月份之外的任何其他月份的问题

发布于 2024-09-25 11:45:01 字数 1756 浏览 1 评论 0原文

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

我将尝试仅发布必要的代码,因此这是我的变量

//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>";

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苄①跕圉湢 2024-10-02 11:45:01

试试这个:

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

并且:

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

Try this:

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

And:

$prevMonth = "{$prevM['year']}-{$prevM['mon']}";
$nextMonth = "{$nextM['year']}-{$nextM['mon']}";
愚人国度 2024-10-02 11:45:01

像这样的东西:

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

Something like:

$date = empty($_GET['currentpage']) ? time() : $_GET['currentpage'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文