我正在尝试根据youtube的视频教程使用php制作日历。我正在做他们所做的事,但他们的桌子有所不同。我找不到我的错误......任何身体帮助请....给出代码和图片....
这是我的日历 -
这是教程日历 -
<html>
<head>
<title>Calender</title>
</head>
<body>
<?php
if(isset($_GET['day']))
{
$day = $_GET['day'];
}else
{
$day = date("j");
}
if(isset($_GET['month']))
{
$month = $_GET['month'];
}else{
$month = date("n");
}
if(isset($_GET['year']))
{
$year = $_GET['year'];
}else{
$year = date("Y");
}
//calender variable-----------
$currentTimeStamp = strtotime($year-$month-$day);
$monthName = date("F",$currentTimeStamp);
$numDays = date("t",$currentTimeStamp);
$counter = 0;
?>
<table border = "1">
<tr>
<th><input style = "width : 50px"type = "button" value = "<" name = "prevbutton"></input></th>
<th colspan = "5"><?php echo $monthName.", ".$year?></th>
<th><input style = "width : 50px" type = "button" value = ">" name = "nextbutton"></input></th>
</tr>
<tr>
<td width = "50px">Sun</td>
<td width = "50px">Mon</td>
<td width = "50px">Tue</td>
<td width = "50px">Wed</td>
<td width = "50px">Thu</td>
<td width = "50px">Fri</td>
<td width = "50px">Sat</td>
</tr>
<?php
echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year-$month-$i);
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td> </td>";
}
}
if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";
?>
</table>
</body>
答案 0 :(得分:1)
PHP代码中有3个错误
echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year.'-'.$month.'-'.$i);// it should be string
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td> </td>"; // show days
}
$counter++; // first row counter correction
}
echo "<td>$i</td>";
if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";