答案 0 :(得分:1)
试试这个
if ($dept == $row["deptNo"]) echo ' selected="selected"';
echo语句中的空格
答案 1 :(得分:0)
试试这个:
<?php
$sql = "SELECT deptNo, deptName FROM Department";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$selected = ($dept == $row["deptNo"]) ? "selected" : "";
?>
<option value= "<?php echo $row['deptNo']; ?>" <?php echo $selected; ?> >
<?php echo $row['deptName']; ?>
</option>
<?php } } ?>
希望这有帮助。
和平!的xD