Here is a function I found years ago and used for a long while. It goes to the db and gets elements for your droplist and matches to the one you want.
PHP Code:
function ListboxMatch($size, $name, $query, $matchtothis) {
mysql_select_db($dbname,$mysql_link);
$qry = mysql_query($query,$mysql_link);
if (mysql_num_rows($qry) > 0)
{ echo "<SELECT SIZE='".$size."' NAME='".$name."'>" , PHP_EOL;
while (list($value, $text) = mysql_fetch_row($qry))
{ echo "\t<OPTION VALUE='".$value."'";
if ($value == $matchtothis)
{ echo " SELECTED"; }
echo ">".$text."</option>" . PHP_EOL;
} echo "</SELECT>" . PHP_EOL;
} else echo "No data in listbox" . PHP_EOL;
mysql_free_result($qry);
}
No guarantee all these mysql_* functions are correct or still exist - but might give you some ideas - it clearly needs some cleaning up (all caps for html elements, wtf?), but still it should work.
PHP Code:
$this_person = 7; // from get or post or session etc
// get 2 things, the value and the text you want to display
$query = "select id, name from people order by name";
// it echoes everything to the screen when called, so put this
// line in the correct place
ListboxMatch(1, 'people', $query, $this_person);
I remember taking this idea and improving it somewhat but I cannot remember where the code is.
Bookmarks