Entry
How do I populate a pulldown menu with data from a mysql table? I'm using Perl & javascript (no PHP
Feb 16th, 2008 02:46
dman, Iain Bruce, Max asdf, http://sturly.com
This answer assumes you are using CGI and DBI Perl modules.
Assuming you have a variable called $page where the HTML stuff will go.
If the database table had information in rows called id and name, then
the following would work:
[snipped db connect]
while ($data = [db stuff]) {
$page .= "<option value=$data->{'id'}>$data->{'name'}";
}
[snipped db disconnect]
$page = "<select name=mydropdown>$page</select>";
$page could then be placed into the HTML output where required, with
the extra form details as necessary.
The DBI module documentation has examples of db connect, db stuff and
db disconnect.
Hope this helps.
www.perl.com, search.cpan.org