Please see this function which populates the combo:
PHP Code:
function PopulateList($table,$valField,$selField,$selId,$param){
$opt = "";
$rs = mysql_query("SELECT $valField,$selField FROM $table WHERE 1 $param ORDER BY $selField ASC") or die(mysql_error());
while($rows = mysql_fetch_array($rs)){
if($rows[$valField] == $selId)
$opt .= "<option value=$rows[$valField] selected>$rows[$selField]</option>";
else
$opt .= "<option value=$rows[$valField]>$rows[$selField]</option>";
}
return $opt;
}
And you can use the function like this:
PHP Code:
<select name="countries" id="countries">
<option selected="selected" value="000">Select Country</option>
<?php echo PopulateList("tablename","id field of the table","field to display","the selected value","pass any parameter");?>
</select>
This is my own function. You can ask more if you don't understand.
Bookmarks