[英]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?
如何将值“ User”和“ Group”添加到此列表的开头? 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>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.