douluokuang7184
2015-09-05 19:15
浏览 29
已采纳

在一个html页面中从mysql开始结束日期和下拉菜单

I am trying to make a html or php page (for some own learning process) which can input 3 selection and then display there results in next page.

1- input Start Date 2- input End Date 3- Show Service Name in drop down menu via mysql query to get services names from the table

So far I have managed to get the start and end table and drop down menu which successfully query the services table and shows the name, but the problem is that when i click submit i can see the results of start and end date but i am unable to see how can i add services selection in the posting. This is my code.

    <!DOCTYPE html>
<html>
    <head>
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
        <script>
            $(document).ready(function() {
                $("#start_datepicker").datepicker();
                $("#end_datepicker").datepicker();
            });
        </script>
    </head>
    <body style="font-size:62.5%;">
        <form action="test.php" method="post">
            Start Date: <input type="text" name="startdate" id="start_datepicker"> <br />
            End Date: <input type="text" name="enddate" id="end_datepicker"><br />
            <select name="srvname">
            <?php
                $conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius')
                or die ('Cannot connect to db');

                $result = $conn->query("select srvname name from rm_services");

                while ($row = $result->fetch_assoc()) {
                    echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
                }
            ?>
            </select>
            <input type="submit" value="Submit:">
        </form>
    </body>
</html>

and this is test.php which will per form action shows the date

  <?php
$STARTDATE = $_POST['startdate'];
$ENDDATE = $_POST['enddate'];
$SRVNAME = $_POST['srvname']; //gets the value -> $row["id"]
echo "<h2>You have entered the following information:</h2>";
echo "<pre>$STARTDATE</pre> ";
echo "<pre>$ENDDATE</pre>";
echo "<pre>$SRVNAME</pre>";
?>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhi6160 2015-09-05 19:53
    已采纳

    This one should work, and for the future: if you post something on stackoverflow, please post formatted code, it's way easier to edit and especially to read it...

    your index.php or whatever...

    <!DOCTYPE html> 
    <html> 
        <head>
            <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
            <script>
                $(document).ready(function() {
                    $("#start_datepicker").datepicker();
                    $("#end_datepicker").datepicker();
                });
            </script> 
        </head> 
        <body style="font-size:62.5%;">
            <form action="test.php" method="post"> 
                Start Date: <input type="text" name="startdate" id="start_datepicker"> <br />
                End Date: <input type="text" name="enddate" id="end_datepicker"><br />
                <select name="srvname">
                <?php
                    $conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius') 
                    or die ('Cannot connect to db');
    
                    $result = $conn->query("select id, name from rm_services");
    
                    while ($row = $result->fetch_assoc()) {
                        echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
                    }
                ?>
                </select>
                <input type="submit" value="Submit:"> 
            </form> 
        </body>
    </html>
    

    your test.php

    <?php
    $STARTDATE = $_POST['startdate'];
    $ENDDATE = $_POST['enddate'];
    $SRVNAME = $_POST['srvname']; //gets the value -> $row["id"]
    echo "<h2>You have entered the following information:</h2>";
    echo "<pre>$STARTDATE</pre> ";
    echo "<pre>$ENDDATE</pre>";
    echo "<pre>$SRVNAME</pre>";
    ?>
    

    I didn't test it, but actually it should work...

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题