我使用下面的代码来显示日历。可以使用href点击日期。唯一的问题是我不知道如何获得链接中的日变量。我可以得到月份和年份。不知道什么选择当天。
电流:
<a href=/page.php?month=$month&year=$year>$i</a>
我需要:
<a href=/page.php?month=$month&day=$day&year=$year>$i</a>
代码:
<?php
$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];
$sel = $_GET["sel"];
$what = $_GET["what"];
$urlprt = $_SERVER['PHP_SELF'];
$qstr = $_SERVER['QUERY_STRING'];
$qss = explode('&',$qstr);
$urllink = $urlprt."?".$qss[0];
if($day == "")
$day = date("j");
if($month == "")
$month = date("F");
if($year == "")
$year = date("Y");
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F",$currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$numEventsThisMonth = 0;
$hasEvent = false;
$todaysEvents = "";
?>
<table align="center" style="border: 0px solid; width:420px; height:300px;">
<tr>
<td width='50' colspan='1'>
<input type='button' value='< ' onClick='goLastMonth(<?php echo $month . ",
" . $year; ?>)' style="border:0px; width:40px;">
</td>
<td width='250' colspan='5' align='center'>
<span><?php echo "Month : ".$month . " &
Year : " . $year; ?></span><br>
</td>
<td width='50' colspan='1' align='right'>
<input type='button' value=' > '
onClick='goNextMonth(<?php echo $month . ",
" . $year; ?>)' style="border:0px; width:40px;">
</td>
</tr>
<tr>
<td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>M</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>W</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>T</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>F</td>
<td class='head' width='30' style='background-color:#FFFFFF;'>S</td>
</tr>
<?php
$numDays = date("t", $currentTimeStamp);
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++)
{
if($j==0)
{
echo "<td style='background-color:#FFFFFF;'> </td>";
}
else
{
echo "<td style='background-color:#FFFFFF;'> </td>";
}
}
}
if($counter % 7 == 0)
{
$counter=0;
echo "</tr><tr>";
if($i == date("d") && $month == date("F") && $year == date("Y"))
{
echo "<td width='30' style='background-color:#FFFFFF;'>
<b><a id=caldates href=/schedule.php?>$i</a></b></td>";
}
else
{
echo "<td width='30' style='background-color:#FFFFFF;'>
<a id=caldates href=/schedule.php?>$i</a> </td>";
}
}
else
{
if($i == date("d") && $month == date("F") && $year == date("Y"))
{
echo "<td width='30' style='background-color:#FFFFFF;'><b><a id=caldates href=/schedule.php?>$i</a></b></td>";
}
else
{
echo "<td width='30' style='background-color:#FFFFFF;'>$i</td>";
}
}
}
?>
<?php
$monthName = date("F", $currentTimeStamp);
?>
</table>
<script>
<?php
$month = date("F");
?>
function goLastMonth(month, year)
{
// If the month is January, decrement the year
if(month == 1)
{
--year;
month = 13;
}
document.location.href = '<?php echo $urllink; ?>&month='+(month-1)+'&year='+year;
}
function goNextMonth(month, year)
{
// If the month is December, increment the year
if(month == 12)
{
++year;
month = 0;
}
document.location.href = '<?php echo $urllink; ?>&month='+(month+1)+'&year='+year;
}
</script>
答案 0 :(得分:1)
我是否误解了这个问题,或者这一天显而易见$i
?