2016-08-31 146 views
-1

我在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> 

但它仍然只給我選擇第一個值。

+0

改進的語法和格式。 – RamenChef

回答

0

您需要在您的<select id="notebboktype" name="notebooktype"多個>

而且無需呼應選定= 「選擇」只是呼應選擇使用

multiple屬性

<select id="notebboktype" name="notebooktype" multiple> 
    <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> 
0
<select id="notebboktype" name="notebooktype" multiple> 
    <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> 


<select id="notebboktype" name="notebooktype" multiple> 
    <option value="Convertible 2 in 1" <?php if ($row['notebooktype'] == "Convertible 2 in 1") echo 'selected'; ?>>Convertible 2 in 1</option> 
    <option value="Notebook" <?php if ($row['notebooktype'] == 'Notebook') echo 'selected'; ?>>Notebook</option> 
    <option value="Ultrabook" <?php if ($row['notebooktype'] == 'Ultrabook') echo 'selected'; ?>>Ultrabook</option> 
    <option value="laptop" <?php if ($row['notebooktype'] == 'laptop') echo 'selected'; ?>>laptop</option> 
</select> 
0

這..

<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> 
相關問題