Re: Database value as selected in combo box!

From: Date: Wed, 10 Sep 2003 16:33:45 +0000
Subject: Re: Database value as selected in combo box!
References: 1  Groups: php.lang 
Request: Send a blank email to php-lang+get-528@lists.php.net to get a copy of this message
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]); > } > } > } > >

« previous php.lang (#528) next »