从下拉菜单中选择更改下拉菜单的内容

时间:2015-05-22 15:48:26

标签: php html

我有一些下拉菜单。如果我选择其中一个,我想用我选择的内容改变其他内容。我怎样才能做到这一点 ?用html和php。

例如,我有一个表

Year   with  id_year  and  year          
Stuff  with  id_stuf  and  stuff

如果我在第一个下拉菜单中选择一年,则在另一个drodown菜单中将仅显示该年的内容。

这是我的下拉菜单

的内容
<div class="view">
    <form name="tabel" method="post" action="insertexamen.php">

    <table>
            <tr>
                <td>Data</td>
                <td><input type="date" name="data" value="data" required="required"/><br></td>
            </tr>

            <tr>
                <td>An</td>
                <td>
                    <?php
                        $sql_year="SELECT * FROM an";
                        $rez_year = mysqli_query($link,$sql_year);
                        echo "<select name=\"year\" >";
                            while($year=mysqli_fetch_array($rez_year))
                            {
                                echo "<option value=\"".$year['id_an']."\">".$year['grupa']."</option>";
                            }
                        echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td>Materie</td>
                <td>
                    <?php
                        $sql_mat="SELECT * FROM materii";
                        $rez_mat = mysqli_query($link,$sql_mat);
                        echo "<select name=\"mat\" >";
                        while($mat=mysqli_fetch_array($rez_mat))
                        {
                            echo "<option value=\"".$mat['id_mat']."\">".$mat['numemat']."</option>";
                        }
                            echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td>Profesor</td>
                <td>
                    <?php
                        $sql_proff="SELECT * FROM profesor";
                        $rez_proff = mysqli_query($link,$sql_proff);

                        echo "<select name=\"proff\" >";
                        while($proff=mysqli_fetch_array($rez_proff))
                        {
                            echo "<option value=\"".$proff['id_prof']."\">".$proff['numep']." ".$proff['prenumep']."</option>";
                        }
                            echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td>Asistent</td>
                <td>
                    <?php
                        $sql_profff="SELECT * FROM profesor";
                        $rez_profff = mysqli_query($link,$sql_profff);

                        echo "<select name=\"profff\" >";
                        while($profff=mysqli_fetch_array($rez_profff))
                        {
                            echo "<option value=\"".$profff['id_prof']."\">".$profff['numep']." ".$profff['prenumep']."</option>";
                        }
                            echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td>Sala</td>
                <td>
                    <?php
                        $sql_room="SELECT * FROM sala";
                        $rez_room= mysqli_query($link,$sql_room);

                        echo "<select name=\"room\" >";
                        while($room=mysqli_fetch_array($rez_room))
                        {
                            echo "<option value=\"".$room['id_s']."\">".$room['salaa']."</option>";
                        }
                            echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td>Tip</td>
                <td>
                    <?php
                        $sql_type="SELECT * FROM examen";
                        $rez_type= mysqli_query($link,$sql_type);

                        echo "<select name=\"type\" >";
                        while($type=mysqli_fetch_array($rez_type))
                        {
                        echo "<option value=\"".$type['id_tip']."\">".$type['tip']."</option>";
                        }
                        echo "</select>";
                    ?><br>
                </td>
            </tr>

            <tr>
                <td><input name="submit" type="submit" value="Trimite"/></td>
                <td><input name="reset" type="reset" value="Reset"/></td>
            </tr>   
</table>

1 个答案:

答案 0 :(得分:0)

你在寻找类似的东西:

count(distinct Real (Color))

如果你只想使用html和php完成它,你将需要使用一些ajax,因为php是服务器端,而html是slient side。所以,为了你的东西我会推荐上面的代码