RE: [PHP] Combo Box containing field
| From: | Don Read | Date: | Sat, 10 Mar 2001 12:21:35 +0000 |
| Subject: | RE: [PHP] Combo Box containing field | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43302@lists.php.net to get a copy of this message | ||
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 dread@texas.net
-- If you are going to sin, sin against God, not the bureaucracy.
God will forgive you but the bureaucrats won't.