On Wednesday, June 13, 2001, at 12:05 PM, Ward, Stefan wrote:
> Does anyone have an example of a way to write a perl script that will
> go out
> hit a data base table, pull in a column for that table and use that
> column
> in a dropdown list? I know what to do once I get that variable
> selected by
> RTFriendlyM, but couldn't find a clear example of this.
>
Gee, you get three responses with books to read, or URLs to visit, but
nobody actually answering your question.
Fucking typical.
Excuse me.
Ok.
So you've read the manual, and you're doing your SELECT from the
database. In many cases, I find myself getting both a value and a human
readable text for my dropdown.
For sake of argument, let's say your dropdown was a list of web pages,
and the VALUE for each <OPTION> is the URL of the page.
So my statements might go something like...
my $sql = "SELECT URL, Name
FROM Links
ORDER BY Name";
my $sth = $dbh->prepare($sql) or die ("Cannot prepare query $sql");
my $sth->execute or die ("Cannot execute query $sql");
my @fields = '';
my $selectstatement = "<SELECT name='Link'>";
while (@fields = $sth->fetchrow_array) {
$selectstatement .= "<OPTION value='$fields[0]'>$fields[1]</OPTION >";
}
$selectstatement .= "</SELECT>";
I hope this answer is more useful than that suggested by the others.