faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 20 people (60%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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