Re: Database value as selected in combo box!

[email protected] ("Patrick") Wed, 10 Sep 2003 12:33:45 -0400
Newsgroups php.lang
Message-ID <[email protected]>
try something like this:

      $query = "SELECT id,name,description from groups ORDER BY id";
      $result = mysql_query($query) or die("Couldn't Retrieve Group
List...<br>");
      while ( $row = mysql_fetch_array($result) )
        {
          $selected = ' ';
          if ( $row["name"] == $editgroupname ) { $selected = ' SELECTED'; }
          $arGroups[] = "         <option value='" . $row["id"] . "'" .
$selected . ">" . $row["name"] . " :: " . $row["description"] .
"</option>\n";
        }
      mysql_free_result($result);

"Anthony Judd" <[email protected]> wrote in message
news:[email protected]...
>
> I am trying to display the current database value as SELECTED in a combo
> box. Any ideas why this isn't working. (ID is being sent).
>
> Would appreciate any help.
>
> function retrieve_category()
> {
>  $cat = mysql_query("SELECT category_id FROM category");
>  while ($current_row = mysql_fetch_row($cat))
>   {
>    if ($current_row[0] == $id)
>         {
>           printf("<option selected>%s</option>\n",$current_row[0]);
>         }
>        else
>         {
>           printf("<option>%s</option>\n",$current_row[0]);
>         }
>   }
> }
>
>