to get the value of selected month and print the dates

前端 未结 2 1379
情深已故
情深已故 2021-01-29 08:05
\"01\",\"February\"=>\"02\",\"March\"=>\"03\",\"April\"=>\"04\",\"May\"=>\"05\",\"June\"=>\"06\",\"July\"=>\"         


        
相关标签:
2条回答
  • 2021-01-29 08:38

    If you want to get the value of the select item use:

    $month = $_POST['month'];
    

    You question makes it uncertain for me if this is all within the same file or not. If this doesn't solve your problem, please let me know in the comments.

    0 讨论(0)
  • 2021-01-29 08:59
    <!DOCTYPE html>
    <html lang="en">
        <body>
    
            <?php
            $month = array("January" => "1",
                "February" => "2",
                "March" => "3",
                "April" => "4",
                "May" => "5",
                "June" => "6",
                "July" => "7",
                "August" => "8",
                "September" => "9",
                "October" => "10",
                "November" => "11",
                "December" => "12");
            ?>
            <form>
                <select name="month">
                    <?php foreach ($month as $key => $value) { ?>
                        <option value="<?php echo $value; ?>">
                            <?php echo $key; ?>
                        </option>
                    <?php } ?>
                </select>
                <input type="submit" name="submit">
            </form>
            <?php
            if (isset($_GET['month'])) {
                $inputMonth = $_GET['month'];
                $mkt = mktime(0, 0, 0, $inputMonth, 1, date("Y"));
                $date2 = date("Y-m-d", $mkt);
                $end2 = date("Y") . "-" . $inputMonth . "-" . date('t', strtotime($date2));
                ?>
                <table>
                    <tr>
                        <?php
                        while (strtotime($date2) <= strtotime($end2)) {
                            $day_num = date('d', strtotime($date2));
                            $day_name = date('l', strtotime($date2));
                            $date2 = date("Y-m-d", strtotime("+1 day", strtotime($date2)));
    
                            echo "<td>$day_num <br/> $day_name</td>";
                        }// end while 
                        ?>
                    </tr>
                </table>
                <?php } //end if 
            ?>
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题