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

在一个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...

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?