来自数据库的下拉列表值(php/sql)

qxgroojn  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(241)

我只是想知道下面的代码是否是用php/sql中的数据库信息填充下拉列表的最有效方法。

//GET ALL SONGS FROM DATABASE
                $query = $dbConn->query("SELECT track_id, track_title FROM track");

                echo '<select class="feild" name="songDrop">';//MAKE THE DROPDOWN 

                echo '<option value="none">Choose the Song to add</option>';

                // Loop through the query results, displaying the options one by one
                while ($row = $query->fetch_assoc()) {
                     echo '<option value="'.$row['track_id'].'">'.$row['track_title'].'</option>';
                }

                echo '</select>';
whitzsjs

whitzsjs1#

试试这个:

//GET ALL SONGS FROM DATABASE
            $query = $dbConn->query("SELECT track_id, track_title FROM track");

            echo '<select class="feild" name="songDrop">';//MAKE THE DROPDOWN 

            echo '<option value="none">Choose the Song to add</option>';

            // Loop through the query results, displaying the options one by one
            while ($row = mysqli_fetch_array($query)) {
                 echo '<option value="'.$row['track_id'].'">'.$row['track_title'].'</option>';
            }

            echo '</select>';

相关问题