PHP的回声选择选项

时间:2018-08-08 11:49:52

标签: php mariadb

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "DBNAMES";
?>
<div>
        <?php
            $conn = new mysqli($servername, $username, $password, $dbname);
            if ($conn->connect_error){
                die("Connection failed: " . $conn->connect_error);
            }
            $sql = "SELECT * FROM names";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                echo "Names: ";
                echo "<select name='siteoption'>";
                while($row = mysqli_fetch_array( $result )) {
                    echo '<option value = "'. $row['ID'] . '">' . $row['Name'] . '</option>';
                }
                echo "</select>";
            }
        ?>
</div>

问题:如何为下拉菜单提供用户无法选择的默认值?

Exp: <option disabled selected value> -- select an option -- </option>我想实现这一目标,但是要使用PHP echo

0 个答案:

没有答案