HighDots Forums  

Populate a select tag from MySQL database

alt.html.writers alt.html.writers


Discuss Populate a select tag from MySQL database in the alt.html.writers forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Nath
 
Posts: n/a

Default Populate a select tag from MySQL database - 12-15-2003 , 09:38 AM






I'm quite new to HTML writing and MySQL, but am learning quickly. I
currently have some code as follows:

Query sequence:
<select name="query" size=1>
<option selected> All </option>
<option> OFSaCe0004 </option>
<option> OFSaCe0157 </option>
<option> OFSaCe0192 </option>
</select>

which i've been using to create a search page to query a MySQL database
i've setup. The options listed in the example are only a small subset of
those that are present in the database, and i would like to know to populate
the <select> tag with options obtained from a MySQL database. Am i able to
do this with a perl (CGI) script, or do i need (or is it easier) to use PHP
(which i also know nothing about)?

The following mysql query will produce an array (@options) that contains all
the appropriate options i wish to use:

my $dsn = "DBI:mysql:database=$db";
my $dbh = DBI->connect($dsn, $user, $password) or die "Cannot connect to
server: $!\n";

my $sth = $dbh->prepare("SELECT search.seq_id, sequence.local_id FROM
search, sequence WHERE search.seq_id=sequence.seq_id GROUP BY seq_id ORDER
BY local_id");
$sth->execute();

my @options;
while ( my $ref = $sth->fetchrow_hashref() ) {
push @options, $ref->{local_id};
}



Thanks for any help.
Nath



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.