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

时间:2014-03-09 01:53:20

标签: php date hyperlink

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

正如您在此DEMO所见,它显示第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>";
}
?>

在其他地方 $ thismonth $ cMonth 不起作用..我正在尝试做我们的这几个,但没有成功......

感谢大家,任何答案!

1 个答案:

答案 0 :(得分:0)

好的,根据您提供的内容,如果我们假设$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>";
}