簡體   English   中英

如何為每月的不同日期賦予唯一的超鏈接?

[英]How to give unique hyperlink to different day of the month?

我在互聯網上找到了這個腳本(日歷),我不知道如何為每月的不同日期提供唯一的超鏈接(a href)。

示例:如果我在第14天點擊,我希望該鏈接將我重定向到google.com
示例:如果第20天= yahoo.com

...

<?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>";
}
?>

感謝大家的任何答復!

使用elseif($ day === number)像這樣:

<?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>";
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM