0

我创建一个这样的下拉列表:

<header>
    <h3 align="center"> Highway State </h3>
</header>
<section>
    <article>
        <hgroup>
        </hgroup>
        <p align="center">
        <form style="text-align:center" method="post" action="">

            <select name="dropdown1">
                <?php echo query1(); ?> 
            </select>

        <input type="submit" value="Submit" />
        </form> 
        </p>
    </article>

其中 query1() 是

function query1()
{
    $myHTMLData = '';
    $c=connect();
    $myData=mysqli_query($c, "SELECT DISTINCT highway_state FROM highways_highway ORDER BY highway_state");
    while($record = mysqli_fetch_array($myData))
    {
        $myHTMLData .= '<option value="' . $record['highway_state'] . '">' . $record['highway_state'] . '</option>' ;
    }
    return $myHTMLData;
}

所以我正在做的是用状态填充下拉菜单。

我现在的问题是如何执行 SELECT ID, exit_name FROM Highways_exit WHERE Highway_ID = (SELECT ID FROM Highways_highway WHERE Highway_state = * dropdown1 *之类的 sql 查询

* dropdown1 *是我希望查询基于 dropdown1 中的选择的位置。我该怎么做呢?

另外:当用户点击提交按钮时,如何在网页上显示此查询?

我对解决方案的尝试(用 index.php 编写)

    <header>
        <h3 align="center">Exit Name</h3>
    </header>
    <section>

        <table border='1' align="center">
            <tr>
            <th>Exit Name</th>
            <th>Exit ID</th>
            </tr>
<?php   
        $c=connect();
        $hstate = $_POST['dropdown1'];
        $hname = $_POST['dropdown2'];
        $hdir = $_POST['dropdown2pt5'];

        $result=mysqli_query($c, "SELECT exit_name, id FROM highways_exit WHERE highway_ID = (SELECT id FROM highways_highway WHERE highway_state = ('" . $hstate . "') AND highway_name = ('" . $hname . "') AND highway_dir = ('" . $hdir . "')) ");  
            while($row = mysqli_fetch_array($result))
            {
                $arrexit = $row['exit_name'];
                $arrid = $row['id'];
                echo "<tr><td>$arrexit</td><td>$arrid</td></tr>";
            }
  ?>
        </table>

    </section>
    <footer>
        <f1 align="center"></f1>
    </footer>

这对使用菜单项是否正确?这个和菜单对象都在 index.php 上,有没有办法让它工作,以便它可以接收菜单项并在刷新/提交时生成这个表?

4

1 回答 1

2

您可以通过使用获取该值,$_POST['dropdown1'] 然后您可以使用它来查询数据库。

于 2013-04-26T01:18:26.327 回答