Posted by Dikkie Dik on 09/26/05 00:04
phpuser32423 wrote:
> Hi everyone
>
> Is it by any chance possible to use mysql and php to auto create the
> content for drop-down lists on forms by retrieving the values from a
> database? The reason i ask is that on a site i am making i am asking
> users to select from list (e.g. nationality) however i would like to
> avoid typing out every possible value of which there are about 40
> (which change). I would much prefer to keep a seperate table in my
> database for the site.
>
> Kind regards
>
> Mcyi2mr3
>
Sure. I assume the database fields have a numeric ID, so you can get the
ID as an answer while the user only sees the description.
Just fetch all the IDs and Descriptions from the database table (if you
order it by description, the user can type the first letter to select
one). Print the HTML for a dropdown list (<SELECT NAME=...>) and the
options. If you are using the ID, print something like:
'<OPTION VALUE=\'' . $ID . '\'>' . $description
for each record in the table
Make it part of a form and it is submitted with it.
Best regards
[Back to original message]
|