0

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.

3
  • 1) Stop using mysql_*, switch to PDO. 2) just echo those 2 options before while. Or add them to DB Commented Nov 23, 2012 at 21:18
  • Can you please elaborate on part 1? Commented Nov 23, 2012 at 21:27
  • just open this page and read red box php.net/manual/en/function.mysql-query.php Commented Nov 23, 2012 at 21:29

1 Answer 1

1

Instead of instantiating the variable with no content ($selection="";), instantiate it with this:

$selection="<OPTION VALUE=\"id\">User</OPTION><OPTION VALUE=\"id\">Group</OPTION>";
Sign up to request clarification or add additional context in comments.

2 Comments

Naturally, you'll want to replace id with the appropriate text/number
Still have a few minutes before it'll let me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.