如何在下个月禁用日历中的活动日期超链接


How to disable active date hyperlink in calender at the next month?

如果更改月份,如何禁用活动超链接?

正如您在这个演示中看到的,它显示,第14和第20个日期是活动的。当我按下"下一步"或"上一页"按钮时,活动链接仍然有效。

我想做的:

我想活动链接将被禁用,如果月是不同的,并有其他活动日期?

代码:

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$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;
}
?>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>">Previous</a>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">Next</a><br/>
<?php echo $monthNames[$cMonth-1].' '.$cYear; ?><br/>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
$day = $i - $startday + 1;
if($i < $startday) {
    echo "<td></td>";
} elseif( ($day === 14) && ($thismonth !== 5) ) {
    echo "<a href='http://google.com/' style='float:left; margin:0px 5px; background:black; color:white;'>". $day . "</a>";
}
elseif( $day === 20) {
    echo "<a href='http://yahoo.com/' style='float:left; margin:0px 5px; background:black; color:white;'>". $day . "</a>";
}
else {
    echo "<a href='#' style='float:left; margin:0px 5px; color:black;'>". $day . "</a>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>

在elseif line $thismonth$cMonth不工作。我正试着做这两件事,但是没有成功……

感谢你们所有人的回答!

根据您提供的内容假设$month_active_days是包含特定月份活动天数的数组您需要将if子句更改为

$month_active_days = array(5, 20); // These are the active days in March for example but you need to have your own process to get the active days in each month like a sql query
...
if($i < $startday) {
   echo "<td></td>";
} elseif( in_array($day, $month_active_days) ) {
   // Do your stuff base on the $day value to show for example a specific link
}
else {
   echo "<a href='#' style='float:left; margin:0px 5px; color:black;'>". $day . "</a>";
}