<?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