【问题标题】:php dropdown boxphp下拉框
【发布时间】:2016-12-02 14:29:54
【问题描述】:

我有一个机场数据库,我有一个网页,目前在表格中显示我的所有结果,
我创建了一个下拉框,以便我可以按航班号细化结果,我可以获得航班号填充,但它似乎不适用于我提交时的页面,我按照我的讲座中的示例进行操作,但仍然无法使其正常工作。任何意见,将不胜感激! =] 附件是我的代码和它目前的样子的屏幕截图。 Airport DB

<?php
if ( isset( $_POST[ 'flight' ] ) ) 
{
    $flightNO = $_POST[ 'flight' ];
} else 
{
    $flightNO = null;
}

$connect = mysqli_connect( "localhost", "root", "" );
mysqli_select_db( $connect, "airportdb" );

?>

<!-- Form --> 
<section id="two" class="wrapper style3">
    <div class="container">
        <h2 align="center">Welcome to Dublin Airport Flight Information Helpdesk</h2>
        <div class="container 50%" align="center">
            <!-- Dropdown Box -->
            <!-- Query -->
            <?php
            $result = mysqli_query( $connect, "select flight from arrivals" );
            ?>
            <form action="arrivals.php" method="post">
                <div class="row uniform" align="center">
                    <div class="6u 12u$(small)">
                        <div class="select-wrapper">
                            <select name="flight">
                                <option value="All">- All -</option>
                                <?php
                                while ( $row = mysqli_fetch_array( $result ) ) {
                                    echo '<option value ="' . $row[ 'flight' ] . ">" . $row[ 'flight' ] . '</option>';

                                }
                                echo '</select>';
                                ?>
                        </div>
                    </div>

                    <div class="6u 12u$(small)">
                        <ul class="actions">
                            <li><input value="Find" class="special" type="submit">
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
        </div>

    </div>
</section>

<!-- Table -->
<section id="three" class=" wrapper style2">
    <div class="container">
        <div class="table-wrapper">

            <?php 
                if(isset($_POST['flight']))
                    $result = mysqli_query($connect, "select * from arrivals where flight='$flightNO'");
                else
                    $result = mysqli_query($connect, "select * from arrivals");

                echo '<h4>Flight Information for '.date('l d F Y'). ', '. date('h:i:s a'). '</h4>';     
                echo '<hr>';
                echo'<table>';
                echo '<thread>
                            <tr>
                                <th><font size="+1">Terminal</th>
                                <th><font size="+1">Origin</th>
                                <th><font size="+1">Airline</th>
                                <th><font size="+1">Flight No</th>
                                <th><font size="+1">Scheduled Date</th>
                                <th><font size="+1">Scheduled Time</th>
                                <th><font size="+1">Status</th>
                            </tr>
                        </thead>';

                while($row=mysqli_fetch_array($result))
                {
                    echo '<tbody align="left">';
                    echo '<tr>';
                    echo '<td>' . $row['terminal'] . '</td>';
                    echo '<td>' . $row['origin'] . '</td>';
                    echo '<td>' . $row['airline'] . '</td>';
                    echo '<td>' . $row['flight'] . '</td>';
                    echo '<td>' . $row['scheduledDate'] . '</td>';
                    echo '<td>' . $row['scheduledTime'] . '</td>';
                    echo '<td>' . $row['status'] . '</td>';
                    echo '</tr>';
                    echo '</tbody>';
                }

                echo '</table>';
                mysqli_close($connect);

            ?>

        </div>
    </div>
</section>
<!--end table php -->

【问题讨论】:

  • 填充选择字段时缺少引号:echo '&lt;option value ="' . $row[ 'flight' ] . "'&gt;"

标签: php html mysql sql


【解决方案1】:

Saerdn 与评论很接近,但由于您使用不同的引号类型,整行有点偏离:

你有:

echo '<option value ="' . $row[ 'flight' ] . ">" . $row[ 'flight' ] . '</option>';

你应该拥有的是:

echo '<option value ="' . $row[ 'flight' ] . '">' . $row[ 'flight' ] . '</option>';

【讨论】:

  • 啊!谢谢 =] 尝试过并且有效 :) 甚至没有注意到它,这是一个愚蠢的错误!
  • 没问题。如果这解决了所有问题,你能接受这个作为答案吗?
【解决方案2】:

你可以试试:

if(!empty($flightNO))

而不是

if(isset($_POST['flight']))

也为了调试,试试

var_dump($flightNO);  

在第一个 if/else 语句的末尾,看看里面有什么。

【讨论】:

    猜你喜欢
    • 2015-02-02
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2017-08-18
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    相关资源
    最近更新 更多