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 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错