使用多个选择选择查询

时间:2015-03-25 21:09:23

标签: php

我是php的初学者。我想从选项中选择部门,在选择部门之后,我想在属于该部门的下一个下拉框中显示roll no。通过提供与我的问题相关的一些想法来帮助我。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Untitled Document</title>
</head>

<body>
<?php include('C:\wamp\www\fms\background.php'); ?>
<?php include('C:\wamp\www\fms\adminmenu.php'); ?>
<?php
if (isset($_POST['delete'])) {
    $con = mysql_connect("localhost", "root", "");

    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    $cid = $_POST['cid'];

    $sql = "DELETE from addpassenger WHERE rno='$rno'";

    mysql_select_db('fms');
    $retval = mysql_query($sql, $con);
    if (!$retval) {
        die('Could not delete data: ' . mysql_error());
    }
    echo "Deleted data successfully\n";
    mysql_close($con);
} else {
    ?>
    <p></p>
    <p></p>
    <p></p>
    <p></p>
    <center>
        <form method="post">
            <table width="344" border="0" cellspacing="1" cellpadding="2">
                <tr>
                    <td>SELECT THE DEPARTMENT</td>
                    <td><?php
                        $con = mysql_connect("localhost", "root", "") or die(mysql_error());
                        $db = @mysql_select_db("fms", $con) or die(mysql_error());
                        $str = "select dept from addpassenger";
                        $res1 = @mysql_query($str);
                        echo '<select name="dept">';
                        echo '<option selected="----------"></option>';
                        while ($row = mysql_fetch_array($res1)) {

                            echo '<option value="' . $row['dept'] . '">' . $row['dept'] . '</option>';
                        }
                        echo '</select>';
                        ?></td>
                </tr>
                <tr>
                    <td width="208">SELECT THE ROLL NO</td>
                    <td width="125">
                        <?php
                        $con = mysql_connect("localhost", "root", "") or die(mysql_error());
                        $db = @mysql_select_db("fms", $con) or die(mysql_error());
                        $str = "select rno from addpassenger ";
                        $res1 = @mysql_query($str);
                        echo '<select name="rno">';
                        echo '<option selected="----------"></option>';
                        while ($row = mysql_fetch_array($res1)) {

                            echo '<option value="' . $row['rno'] . '">' . $row['rno'] . '</option>';
                        }
                        echo '</select>';
                        ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="208"></td>
                    <td></td>
                </tr>
                <tr>
                    <td width="208"></td>
                    <td>
                        <input name="delete" type="submit" id="delete" value="Delete">
                    </td>
                </tr>
            </table>
        </form>
    </center>
<?php
}
?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

select rno from addpassenger

需要有一个where子句,根据之前的选择选择