Home  |  Linux  | Mysql  | PHP  | XML
From:Patrick Date:Wed Sep 10 10:33:45 2003
Subject:Re: Database value as selected in combo box!
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" <anthonyjudd@tpg.com.au> wrote in message
news:20030202062131.54141.qmail@pb1.pair.com...
>
> 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]);
>         }
>   }
> }
>
>
Navigate in group php.lang at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants