使用php更改基于下拉选择的循环更改mysql查询

时间:2016-07-20 07:20:15

标签: php jquery mysql

我有一个包含多个名字的下拉列表。现在,我无法根据下拉列表选择如何更改查询。要更改的查询还会显示一个课程列表。这只是我一直在努力纳入我的投资组合的项目的一部分。感谢。

这是下拉列表的代码。

                           <select class="form-control" name="courses" id="courses">
                                <?php 
                                    $sql = "SELECT student_name FROM tbl_students";
                                    $res = mysqli_query($conn,$sql);
                                    echo "<option>---SELECT STUDENT---</option>";
                                    while ($row = mysqli_fetch_array($res)){
                                    echo "<option value=".$row['student_name'].">" . $row['student_name'] . "</option>";
                                    }
                                ?>
                            </select>

这里有一个列表,其中有一个查询需要在选择上面代码的下拉列表时进行更改。

$sql="SELECT distinct sbj_name FROM tbl_courses_subject";
                        $result = mysqli_query($conn,$sql);
                        $rank = 1;


                        while ($row = mysqli_fetch_array($result)) {
                        $sub_name = $row['sbj_name'];
                        echo "<div class='container'>";
                            echo "<div class='panel-group'>";
                                echo "<div class='panel panel-default'>";
                                    echo "<div class='panel-heading'>";
                                        echo "<h4 class='panel-title'>";
                                            echo "<a class='accordion-toggle' data-toggle='collapse' data-parent='#course10".$rank."' href='#course10".$rank."'>";

                                                echo "<td>{$sub_name} <br /> </td>";

                                            echo "</a>";
                                        echo "</h4>";
                                    echo "</div>";
                                echo "</div>";
                            echo "</div>";
                            echo "<div id='course10".$rank."' class='accordion-body collapse'>";
                                echo "<div class='accordion-inner'>";
                                    echo "<table class='table'>";
                                        echo "<thead>";
                                            echo "<tr>";
                                                echo "<th></th>";
                                                echo "<th>Subject Time</th>";
                                                echo "<th>Subject Day</th>";
                                                echo "<th>Professor</th>";
                                                echo "<th>Units</th>";
                                            echo "</tr>";
                                        echo "</thead>";
                                        $sql1="SELECT sbj_id, sbj_sched, sbj_sched_day, sbj_prof,sbj_units FROM tbl_courses_subject where sbj_name ='".$sub_name."'";
                                        //echo $sql1;
                                        $result1 = mysqli_query($conn,$sql1);
                                        while ($row1 = mysqli_fetch_array($result1)) {
                                        echo "<tbody>";
                                            echo "<tr>";
                                                echo "<td><input type='radio' name='subject' id='".$row1['sbj_id']."'></td>";
                                                echo "<td>{$row1['sbj_sched']}</td>";
                                                echo "<td>{$row1['sbj_sched_day']}</td>";
                                                echo "<td>{$row1['sbj_prof']}</td>";
                                                echo "<td>{$row1['sbj_units']}</td>";
                                            echo "</tr>";
                                        echo "</tbody>";
                                        }
                                    echo "</table>";

                                echo "</div>";
                            echo "</div>";
                        echo "</div>";

                                    $rank++;        
                                }

0 个答案:

没有答案