On 10-Mar-01 RealGM wrote:
> Hi,
>
> Does anyone know how I can create a combo box in my php file that reads the
> options in from a database field?
>
> I can create combo boxes fine containing values that I enter, but I want it
> to read the values from the database into the drop down box for the user to
> select.
>
> Thanks,
> Michael.
>
function selectoption($k, $v, $comp) {
printf("<OPTION VALUE=\"%s\" %s>%s</OPTION>\n",
$k, $comp == $k ? "SELECTED" :"", $v);
}
$qry="select id,name)
from country order by name";
$dbres = @mysql_query($qry);
if ($dbres) {
echo '<SELECT NAME=country SIZE="5">';
while ( $row = mysql_fetch_object($dbres)) {
selectoption($row->id, $row->name, $usercountry);
}
echo "</SELECT>\n";
}
Regards,
--
Don Read [EMAIL PROTECTED]
-- If you are going to sin, sin against God, not the bureaucracy.
God will forgive you but the bureaucrats won't.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]