如何将某一天选为 多变的
我正在使用下面的代码来显示日历。可以使用 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>
I am using the code below to show a calendar. The days are clickable using a href. The only problem is i don't know how to get the day variable in the link. I can get the month and year. NOt sure what do pick as the day.
current:
<a href=/page.php?month=$month&year=$year>$i</a>
I need:
<a href=/page.php?month=$month&day=$day&year=$year>$i</a>
code:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是否误解了这个问题,或者这一天很明显是
$i
?Did I misunderstood the question or is it obvious the day is
$i
?