douji8347 2017-04-10 07:37
浏览 54
已采纳

从两个相应的下拉列表中填充所选月份和年份的日期和日期

I need to display days of selected month and date on press of Go button.

I have tried REQUEST and GET to get it from URL, onchange() but I am definitely doing something wrong. I know that the current code is static and displays values of only 9th month of 2003.

<table>
<tr>
    <form id="frmA" class="form-inline" role="form" >
        <td align="right">
            <select id="month" name="month" class="form-control" required="required">
                <option value="">Select Month...</option>
                <option value='1'>January</option>
                <option value='2'>February</option>
                <option value='3'>March</option>
                <option value='4'>April</option>
                <option value='5'>May</option>
                <option value='6'>June</option>
                <option value='7'>July</option>
                <option value='8'>August</option>
                <option value='9'>September</option>
                <option value='10'>October</option>
                <option value='11'>November</option>
                <option value='12'>December</option>
            </select>
        </td>
        <td>  
            <select id="year" name="year" class="form-control" required="required">
            <?php 
                foreach (range(date('Y'), $earliest_year) as $x) {
                print '<option value="'.$x.'"'.($x === $already_selected_value ? ' 
                selected="selected"' : '').'>'.$x.'</option>';}
                ?>
            </select>
        </td>
        <td>
            <input type="submit" value="Go!" />
        </td>
    </form>
</tr>
<table>
    <tbody>
        <?php
            $date = '2003-09-01';
            $end = '2003-09-' . date('t', strtotime($date)); 
            i=1;
            while(strtotime($date) <= strtotime($end) && $i <= strtotime($end))  {
                $day_num = date("d/m/Y", strtotime($date));
                $day_name = date('l', strtotime($date));
                $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
                echo "<tr><td>$day_num - $day_name</td></tr>";
                i++;
            }
            ?>
    </tbody>
</table>
  • 写回答

2条回答 默认 最新

  • doudunyi3796 2017-04-10 08:33
    关注

    you lack a few things in your code : 1/ a method + an action in 'form' 2/ assign $vars before using them on line -> $date = '2003-09-01';

     <table>
    <tbody>
    <?php
    
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $month = $_POST['month'];
    $year = $_POST['year'];
    
    $date = "$year-$month-01";
    $end = "$year-$month-" . date('t', strtotime($date)); 
    
    echo"[ $month / $year / $date / $end ]";
    /* code below will throw an error 
    $i=1;
    while( (strtotime($date) <= strtotime($end)) && ($i <= strtotime($end))      )  {
    $day_num = date("d/m/Y", strtotime($date));
    $day_name = date('l', strtotime($date));
    $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
    echo "<tr><td>$day_num - $day_name</td></tr>";
    i++;
    }
    */
    ?>
    </tbody>
    </table>
    
    <table>
    <tr>
    <form id="frmA" class="form-inline" role="form" method="post" action="mypage.php" >
    <td align="right">
    
    <select id="month" name="month" class="form-control" required="required">
                        <option value="">Select Month...</option>
                        <option value='1'>January</option>
                        <option value='2'>February</option>
                        <option value='3'>March</option>
                        <option value='4'>April</option>
                        <option value='5'>May</option>
                        <option value='6'>June</option>
                        <option value='7'>July</option>
                        <option value='8'>August</option>
                        <option value='9'>September</option>
                        <option value='10'>October</option>
                        <option value='11'>November</option>
                        <option value='12'>December</option>
      </select>
    </td>
    
    <td>  
    <select id="year" name="year" class="form-control" required="required">
    <?php
    foreach (range(date('Y'), $earliest_year) as $x) {
    print '<option value="'.$x.'"'.($x === $already_selected_value ? ' 
    selected="selected"' : '').'>'.$x.'</option>';}
    ?>
    </select>
    </td>
    
    <td>
    <input type="submit" value="Go!" />
    </td>
    </form>
    </tr></tbody>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了