简体   繁体   中英

Populating php drop down with additional values

I have a drop down list that is generated from values in a table, however, there are two additional values I'd like to add that are not in this table.

$sql = mysql_query("select category_id,category_name from categories"); 
    $selection="";
    while ($row=mysql_fetch_array($sql)){ 
        $id=$row["category_id"]; 
        $category_name = $row["category_name"]; 
        $selected = ($id == $idlookup) ? 'selected="selected"' : '';
        $selection.="<OPTION " . $selected . " VALUE=\"$id\">".$category_name."</OPTION>";
    }

<tr><td><input type = "text" name ="search_value"></input></td><td><select name ="category"><Option >Choose Category<? echo $selection; ?></Select></td>

This works fine, but I'm not sure how to add two more values to the beginning of the list. How could I add the values "User" and "Group" to the beginning of this list? I do not want them in the categories table because this will only be used on one page.

而不是实例化不带任何内容的变量( $selection=""; ),而是使用以下方法实例化它:

$selection="<OPTION VALUE=\"id\">User</OPTION><OPTION VALUE=\"id\">Group</OPTION>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM