我在select中有四個值,而在數據庫中可能只有兩個從它們存儲的值。從數據庫中選擇下拉列表中的值
<select id="notebboktype" name="notebooktype">
<option value="Convertible 2 in 1">Convertible 2 in 1</option>
<option value="Notebook">Notebook</option>
<option value="Laptop">Laptop</option>
<option value="Ultrabook">Ultrabook</option>
</select>
如何獲得選定值。我試過這個:
<option value="Convertible 2 in 1" <?php if ($row['notebooktype'] == "Convertible 2 in 1") echo 'selected = "selected"'; ?>>Convertible 2 in 1</option>
<option value="Notebook" <?php if ($row['notebooktype'] == 'Notebook') echo 'selected = "selected"'; ?>>Notebook</option>
<option value="Ultrabook" <?php if ($row['notebooktype'] == 'Ultrabook') echo 'selected = "selected"'; ?>>Ultrabook</option>
<option value="laptop" <?php if ($row['notebooktype'] == 'laptop') echo 'selected = "selected"'; ?>>laptop</option>
但它仍然只給我選擇第一個值。
改進的語法和格式。 – RamenChef