为什么我做的日历跟真实情况不一样呢?

为什么我做的日历跟真实情况不一样呢?

这是我在看PHP+MYSQL网站设计入门视频教程时跟着做的万年历,.代码如下
<?php
if(!$SelectedYear){
     $SelectdYear=date('Y');
}
if(!$SelectedMonth){
    $SelectedMonth=date('m');
}
if(!$SelectdeDay){
    $SelectedDay=date('d');
}
$firstday=date('w',mktime(0,0,0,$SelectedMonth,$SelectedDay,$SelectedYear));
$lastday=31;
$month1=date('m',mktime(0,0,0,$SelectedMonth,1,$SelectedYear));
$month2=date('m',mktime(0,0,0,$SelectedMonth,$lastday,$SelectedYear));
if($month1!=$month2){
    $lastday--;
}
$MonthName=date('F',mktime(0,0,0,$SelectedMonth,1,$SelectedYear));
$days=array('Sun','Mon','Tue','Wed','Thu','Fri','Sat',);
echo "<table bgcolor=\"#cccccc\">";
echo "<caption valign=\"center\"><b>$MonthName $SelectdYear</b></caption>";
echo "<tr>";
for($i=0;$i<7;$i++){
    echo "<td width=10%>$days[$i]</td>";
}
echo "</tr>";
echo "<tr>";
$dayrow=0;
while($dayrow<$firstday){
    echo "<td></td>";
    $dayrow++;
}
$day=0;
while($day<$lastday)
{
    if($dayrow%7==0)
    {
    echo "</tr><tr>";
    }
    $day++;
    echo "<td>$day</td>";
    $dayrow++;
}
echo "</tr></table>";

功能还不完整,调试后输出的是这个月的日历,可是却发现跟真实情况对不上!
希望有人能帮我看看,有些地方我也不是很明白...
比如说$dayrow(代表日子在表格中显示的位置)为什么初始值是0而不是1...

看来问题挺多的,比如$SelectdYear,但你一会有写成$SelectedYear。你看看这两个是否一样。
另外这个我blog的一个日历的写法,你可以参考下

[复制到剪切板]
CODE:
<?php
if(!isset($year))
    
$year date("Y");

if(!isset(
$month))
    
$month date("m");

$first_timestamp strtotime("{$year}-{$month}-1");
$last date("t"strtotime("{$year}-{$month}-1"));
$last_timestamp strtotime("{$year}-{$month}-{$last}");

$before date("w"$first_timestamp);
$after date("w"$last_timestamp);

$arr = array();
for (
$i=$before$i>=1$i--){
    
$timestamp strtotime("-{$i} day"$first_timestamp);
    
$arr[] = array(
        
"timestamp" => $timestamp,
        
"day" => date("j"$timestamp),
        
"date" => date("Ymd"$timestamp),
        
"belong" => "other"
    
);
}

for (
$i=1$i<=$last$i++){
    
$timestamp strtotime("{$year}-{$month}-{$i}");
    
$arr[] = array(
        
"timestamp" => $timestamp,
        
"day" => date("j"$timestamp),
        
"date" => date("Ymd"$timestamp),
        
"belong" => (date("Ymd") == date("Ymd"$timestamp)? "today""index")
    );
}

for (
$i=1$i<=$after$i++){
    
$timestamp strtotime("+{$i} day"$last_timestamp);
    
$arr[] = array(
        
"timestamp" => $timestamp,
        
"day" => date("j"$timestamp),
        
"date" => date("Ymd"$timestamp),
        
"belong" => "other"
    
);
}
echo <<<EOT
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="calendar_tb">
  <tbody>
  <tr>
    <td>日</td>
    <td>一</td>
    <td>二</td>
    <td>三</td>
    <td>四</td>
    <td>五</td>
    <td>六</td>
  </tr>
EOT;
foreach (
$arr as $key => $cal){
if((
$key+1)%== 1){
echo <<<EOT
  <tr>
EOT;
}
echo <<<EOT
    <td class="{$cal['belong']}">
    
{$cal['day']}
    </td>
EOT;
if((
$key+1)%== 0){
echo <<<EOT
  </tr>
EOT;
}
}
echo <<<EOT
  </tbody>
</table> 
EOT;
?> ;


毕业了。。。

恩,谢谢,我再检查检查...

我把你说的那个拼写错误改过来以后,就好了。。。

非常感谢!