It depends on what you want to do with this - if you are simply building a menu from available entries in a database - I'd put the entries in an array, then do a for loop like:
print "<SELECT NAME=Company_Name>\n";
foreach (@company) {
print "<OPTION VALUE=$_>$_\n";
}
print "</SELECT>\n";
However, if you want to do something more complex, like are editing that Company_Name field by using a drop down menu it's a bit more complex, because you've got to distinguish which option should be checked.
| [reply] [d/l] |
I understand how to use the <SELECT> and <OPTION> tags. My question is how do you pull the first entry, in the example database, to be the OPTIONs?
Thank you | [reply] |
You'll need to provide a little more information than this. In specific, what kind of database is it and what method are you using to pull it (eg, it's a MySQL database and I'm using DBI to interface with it)?
| [reply] |
something like this: not completely correct i think...
use CGI;
use DBI;
use strict;
my $q = new CGI;
print $q->header();
print "<html><form><select>\n";
my $dbh = DBI->connect(&DSN, &USER, &PASS);
my $sth = $dbh->prepare("SELECT memberID, membername FROM members");
$sth->execute();
while( my ($memberID, $membername) = $sth->fetchrow_array() ) {
print "<option value="$memberID">$membername \n";
}
| [reply] |
it erased my formating... the first time..
something like this: not completely correct i think...
use CGI;
use DBI;
use strict;
my $q = new CGI;
print $q->header();
print "<html><form><select>\n";
my $dbh = DBI->connect(&DSN, &USER, &PASS);
my $sth = $dbh->prepare("SELECT memberID, membername FROM members");
$sth->execute();
while( my ($memberID, $membername) = $sth->fetchrow_array() ) {
print "<option value="$memberID">$membername \n";
}
| [reply] |