duancan9815 2014-04-24 02:13
浏览 40
已采纳

为什么这个PHP代码在年份和月份没有显示我的日历?

I select the dropdowns and nothing populates. I am not sure why? I am new to php so any help is much appreciated.

here is my code:

<section id="content" class="planner">  
<select id="month" name="month">                      
  <option value="0">--Select Month--</option>
  <option value="January">January</option>
  <option value="Februrary">February</option>
  <option value="March">March</option>
  <option value="April">April</option>
  <option value="May">May</option>
  <option value="June">June</option>
  <option value="July">July</option>
  <option value="August">August</option>
  <option value="September">September</option>
  <option value="October">October</option>
  <option value="November">November</option>
  <option value="December">December</option>
</select>

<select id="year" name="year">                      
  <option value="0">--Select Year--</option>
  <option value="2010">2010</option>
  <option value="2011">2011</option>
  <option value="2012">2012</option>
  <option value="2012">2013</option>
  <option value="2012">2014</option>
  <option value="2012">2015</option>
  <option value="2012">2016</option>
</select>

<table class="month">
    <tr class="days">
        <td>Mon</td>
        <td>Tues</td>
        <td>Wed</td>
        <td>Thurs</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
<?php 

        if($_POST['month'] && $_POST['year'] != 0)
        {
           $today = date("d"); // Current day
           $month=$_POST['month'];
           $year=$_POST['year'];
           GenerateCalendar($today,$month,$year);
        }

        function GenerateCalendar($today,$month,$year)
        {
            $today = date("d"); // Current day
            $days = cal_days_in_month(CAL_GREGORIAN,$month,$year); // Days in current month

            $lastmonth = date("t", mktime(0,0,0,$month-1,1,$year)); // Days in previous month

            $start = date("N", mktime(0,0,0,$month,1,$year)); // Starting day of current month
            $finish = date("N", mktime(0,0,0,$month,$days,$year)); // Finishing day of  current month
            $laststart = $start - 1; // Days of previous month in calander

            $counter = 1;
            $nextMonthCounter = 1;

            if($start > 5){ $rows = 6; }else {$rows = 5; }

            for($i = 1; $i <= $rows; $i++){
                    echo '<tr class="week">';
                    for($x = 1; $x <= 7; $x++){             

                            if(($counter - $start) < 0){
                                    $date = (($lastmonth - $laststart) + $counter);
                                    $class = 'class="blur"';
                            }else if(($counter - $start) >= $days){
                                    $date = ($nextMonthCounter);
                                    $nextMonthCounter++;

                                    $class = 'class="blur"';

                            }else {
                                    $date = ($counter - $start + 1);
                                    if($today == $counter - $start + 1){
                                            $class = 'class="today"';
                                    }
                            }


                            echo '<td '.$class.'><a class="date">'. $date . '</a></td>';

                            $counter++;
                            $class = '';
                    }
                    echo '</tr>';
            }
        }

?>
</table>
</section>
  • 写回答

1条回答 默认 最新

  • duandunzhuo3234 2014-04-24 02:31
    关注

    You are missing the html <form> tags around your select statements. You are also going to need an input type submit to send the form

    <form action="" method="POST" name="myForm">
        <!--YOUR SELECTS-->
        <input type="submit" value="SEND THIS FORM"/>
    </form>
    

    the form action"" sends the post data to your current page. The method is either POST or GET. You are using POST.

    That's all. You should consider learning HTML basics before continuing onto php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?