Php 如何为每个月的不同日期提供唯一的超链接?
我在互联网上找到了这个脚本(日历),我不知道如何为一个月的不同日子提供唯一的超链接(a href) 示例:如果我在第14天单击,我希望该链接将我重定向到google.comPhp 如何为每个月的不同日期提供唯一的超链接?,php,date,calendar,Php,Date,Calendar,我在互联网上找到了这个脚本(日历),我不知道如何为一个月的不同日子提供唯一的超链接(a href) 示例:如果我在第14天单击,我希望该链接将我重定向到google.com 示例:如果第20天=yahoo.com 谢谢大家的回答 像这样使用elseif($day===number): 您好,谢谢您的回答,但我在第49行收到了这些错误:解析错误:语法错误,意外的“else”(T_else);与elseif相同:/s忘记了开口支架sry。我刚刚编辑了帖子,请再试:)不客气:)请接受正
示例:如果第20天=yahoo.com
谢谢大家的回答 像这样使用elseif($day===number):
您好,谢谢您的回答,但我在第49行收到了这些错误:解析错误:语法错误,意外的“else”(T_else);与elseif相同:/s忘记了开口支架sry。我刚刚编辑了帖子,请再试:)不客气:)请接受正确答案。谢谢,已经做了!再次感谢您,祝您在使用其他代码时好运!还有一个问题:几个月怎么样?因为,如果我单击“下一个”月按钮,则第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>";
if($i < $startday) echo "<td></td>";
else echo "<a href='#' style='float:left; margin:0px 5px;'>". ($i - $startday + 1) . "</a>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
<?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) {
echo "<a href='http://google.com/' style='float:left; margin:0px 5px;'>". $day . "</a>";
}
elseif( $day === 20) {
echo "<a href='http://yahoo.com/' style='float:left; margin:0px 5px;'>". $day . "</a>";
}
else {
echo "<a href='#' style='float:left; margin:0px 5px;'>". $day . "</a>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>