JavaScript日历无效

时间:2016-01-24 14:02:04

标签: javascript php

我正在尝试根据youtube的视频教程使用php制作日历。我正在做他们所做的事,但他们的桌子有所不同。我找不到我的错误......任何身体帮助请....给出代码和图片....

这是我的日历 -

calender

这是教程日历 -

calender

<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>&nbsp</td>"; 
                        }
                    }
                    if($counter%7==0)
                    {
                        echo "</tr><tr>";
                    }
                }
            echo "</tr>";
        ?>

    </table>
</body>

1 个答案:

答案 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>&nbsp</td>"; // show days
                    }
                  $counter++;  // first row counter correction
                }

                     echo "<td>$i</td>";

                if($counter%7==0)
                {
                    echo "</tr><tr>";
                }
            }
        echo "</tr>";