更改年份时找不到PHP投掷页中的日历

时间:2018-11-07 00:55:41

标签: php calendar

我有一些php代码,以日历格式显示当前月份,并且在日历顶部具有一些导航链接,这些链接允许每月进行导航(下一个和上一个)。

下面的代码是-我从另一个来源(不是我的代码)那里借来的,我的想法使我无法确定在哪里,道歉或我援引该来源。对我有用。

我发现的错误是,当尝试导航到当前年份以外的年份(向前和向后)时-我的网站(这是一个wordpress网站)抛出未找到页面错误。我有些困惑,请问这里的智者吗?

if (!isset($_REQUEST['month'])) $_REQUEST['month'] = date('n');
if (!isset($_REQUEST['year'])) $_REQUEST['year'] = date('Y');
$cMonth = $_REQUEST['month'];
$cYear = $_REQUEST['year'];

... more code in between...

$month = strftime('%m', time());
$cur_year = strftime('%Y', time());
$monthNames = Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
}

...more code here not really relevant...

echo "<div class='box-a-program'><table class='calendar-direction'><tr>
<td width='33%'><a href='/client-meal-calendar/?month=".$prev_month."&year=".$prev_year."'>Previous</a></td>
<td width='33%'><a href='/client-meal-calendar/?month=".$month."&year=".$cur_year."'>Today</a></td>
<td width='33%'><a href='/client-meal-calendar/?month=".$next_month."&year=".$next_year."'>Next</a></td>
</tr></table>

<table class='calendar'><tr><th colspan='7'><strong>".$monthNames[$cMonth-1]." ".$cYear."</strong></th></tr>

<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr><tbody>";

$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date('t',$timestamp);
$thismonth = getdate($timestamp);
$startday = $thismonth['wday'];
$today_number = strftime("%e",time());
$today_number = (int)$today_number;

for ($i=0; $i<($maxday+$startday); $i++) {

    if ((($i - $startday + 1) == $today_number) && ($cMonth == $month)) {
        $wrap = "today";
    } else {
        $wrap = "nottoday"; }

    if(($i % 7) == 0 ) echo "<tr>";

    if($i < $startday) {
        echo "<td></td>";
    } else {

...some more code that does things in here...

        echo "<td height='20px' class=".$wrap.">".($i - $startday + 1). ...some code in here for some form work ... </td>"; 
    }

    if(($i % 7) == 6 ) echo "</tr>";
}

echo "</tbody></table></div>";

编辑:对不起,我应该澄清一下。我要问的是,从当前年的12月到明年的1月,或者从今年的1月到上一年的12月,有人能看到代码中的错误吗? / p>

1 个答案:

答案 0 :(得分:0)

我是个傻瓜。这几乎是与here

相同的问题

答案是更改$ _GET中使用的变量,以及随后在代码中使用的变量。月和年是保留名称。

...针对未开始的人进行欺骗。