php 带有上一个和下一个的日历未重新加载页面

php calendar with previous and next not reloading the page

我需要在页面的侧边栏中包含一个 php 日历。

我正在使用我几周前发现的片段,因为我以前用过它并且工作正常。但是这次,我必须添加下一个和上一个按钮来显示上个月或下个月...

我的问题是...我需要修改生成当前月份的 php 吗?

这是我目前拥有的:

    <table class="month">
    <tr class="days">
        <td>Mon</td>
        <td>Tues</td>
        <td>Wed</td>
        <td>Thurs</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
        <?php 

    $today = date("d"); // Current day
    $month = date("m"); // Current month
    $year = date("Y"); // Current year
    $days = cal_days_in_month(CAL_GREGORIAN,$month,$year); // Days in current month

    $lastmonth = date("t", mktime(0,0,0,$month-1,1,$year)); // Days in previous month

    $start = date("N", mktime(0,0,0,$month,1,$year)); // Starting day of current month
    $finish = date("N", mktime(0,0,0,$month,$days,$year)); // Finishing day of  current month
    $laststart = $start - 1; // Days of previous month in calander

    $counter = 1;
    $nextMonthCounter = 1;

    if($start > 5){ $rows = 6; }else {$rows = 5; }

    for($i = 1; $i <= $rows; $i++){
        echo '<tr class="week">';
        for($x = 1; $x <= 7; $x++){             

            if(($counter - $start) < 0){
                $date = (($lastmonth - $laststart) + $counter);
                $class = 'class="blur"';
            }else if(($counter - $start) >= $days){
                $date = ($nextMonthCounter);
                $nextMonthCounter++;

                $class = 'class="blur"';

            }else {
                $date = ($counter - $start + 1);
                if($today == $counter - $start + 1){
                    $class = 'class="today"';
                }
            }


            echo '<td '.$class.'><span class="dayWrap">'. $date . '</span></td>';

            $counter++;
            $class = '';
        }
        echo '</tr>';
    }

?>
</table>
  <div class="changeMonthLinks">
  <a class="col-xs-12" href="">< Prev</a>
  <a class="col-xs-12 aright" href="">Next ></a>
  </div>

我只是不知道如何继续...或者我需要在锚标签中添加什么 :S

任何帮助将不胜感激。

谢谢 谢谢!!

我在 url 中为参数 ?now 添加了 $now,我正在用 strtotime 将其解析为变量 $dtNow,所有日期函数都已扩展,底部的链接是延长 ?now=$dtNow + 1 个月和 ?now=$dtNow - month

这是代码

<?php

$now = '';
if(isset($_GET['now']))
    $now = $_GET['now'];

$dtNow = strtotime($now);
if(!$dtNow)
{
    $dtNow = time();
}
echo "<h1>Today is " . date('Y-m-d', $dtNow) . "</h1>";

?>
<table class="month">
    <tr class="days">
        <td>Mon</td>
        <td>Tues</td>
        <td>Wed</td>
        <td>Thurs</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
    <?php


    $today = date("d", $dtNow); // Current day
    $month = date("m", $dtNow); // Current month
    $year = date("Y", $dtNow); // Current year
    $days = cal_days_in_month(CAL_GREGORIAN,$month,$year); // Days in current month

    $lastmonth = date("t", mktime(0,0,0,$month-1,1,$year)); // Days in previous month

    $start = date("N", mktime(0,0,0,$month,1,$year)); // Starting day of current month
    $finish = date("N", mktime(0,0,0,$month,$days,$year)); // Finishing day of  current month
    $laststart = $start - 1; // Days of previous month in calander

    $counter = 1;
    $nextMonthCounter = 1;

    if($start > 5){ $rows = 6; }else {$rows = 5; }

    for($i = 1; $i <= $rows; $i++){
        echo '<tr class="week">';
        for($x = 1; $x <= 7; $x++){

            if(($counter - $start) < 0){
                $date = (($lastmonth - $laststart) + $counter);
                $class = 'class="blur"';
            }else if(($counter - $start) >= $days){
                $date = ($nextMonthCounter);
                $nextMonthCounter++;

                $class = 'class="blur"';

            }else {
                $date = ($counter - $start + 1);
                if($today == $counter - $start + 1){
                    $class = 'class="today"';
                }
            }


            echo '<td '.$class.'><span class="dayWrap">'. $date . '</span></td>';

            $counter++;
            $class = '';
        }
        echo '</tr>';
    }

    ?>
</table>
<div class="changeMonthLinks">
    <a class="col-xs-12" href="?now=<?php echo date('Y-m-d', $dtNow - 30*24*60*60); ?>">< Prev</a>
    <a class="col-xs-12 aright" href="?now=<?php echo date('Y-m-d', $dtNow + 30*24*60*60); ?>">Next ></a>
</div>