Three tips to set you on your way :
- use DBI, the standard database interface driver
- DBD::Oracle, the standard oracle interface library
- use CGI, the standard web library
These libraries are all available on CPAN
Jorg
"Do or do not, there is no try" -- Yoda | [reply] |
Take a look at the HTML::Template module. It allows you to build a hash containing the list box entries, while keeping your HTML code simple. Here's an excerpt from code using HTML::Template. It builds table rows of check boxes, rather than list box entries, but the code would be similar.
Sample perl (using DBI):
while ($sth->fetch) {
my %hash = (description => $description, itemNum => $itemNum);
push @items, \%hash;
}
$tmpl->param(items => \@items);
Corresponding template excerpt:
<TMPL_LOOP name="items">
<tr>
<td>
<INPUT id=<TMPL_VAR name="itemNum"> name=<TMPL_VAR name="itemNum">
+ type=checkbox>
<LABEL for="<TMPL_VAR name="itemNum">"><TMPL_VAR name="description
+"></LABEL>
</td>
</tr>
</TMPL_LOOP>
| [reply] [d/l] [select] |
Like the monks have said, DBI is the way to go. This is the
standard way to connect to a database in Perl, and has been for a
while. This example uses DBI to do the same thing with a mysql
database, the only difference in using Oracle is that the connection
routine would have to change and you would have to use DBD::Oracle.
(you have to set some env variables when connecting, ORACLE_HOME, and ORACLE_SID, i
believe, but check out the docs).
Anyway, the get_catnames() routine which returns a reference to an array
which is handed over to the CGI.pm popup_menu() function would work
just the same in oracle, providing it was working with a valid $dbh.
#!/usr/bin/perl -Tw
use strict;
use CGI qw# :standard :form #;
use DBI;
use DBD::mysql;
my $dbh = get_handle('dbname', 'dbuser', 'dbpasswd');
my $listref = get_catnames( \$dbh ); # sending a ref
print header;
print start_html;
print popup_menu( -name=>'categories', -value=>$listref );
$dbh->disconnect;
#####
#####
sub get_catnames {
my $dbh = shift;
my @cats = ();
my $statement = "select category_name from mtx_catnames";
my $sta = $$dbh->prepare($statement); # deref this
$sta->execute;
my $cats = $sta->fetchall_arrayref;
for my $row ( @{ $cats } ) {
push @cats, $row->[0];
}
return \@cats;
}
sub get_handle {
my ($DB, $DBUSER, $DBPASS) = @_;
my $dsn = "DBI:mysql:database=$DB;host=localhost";
my $dbh = DBI->connect($dsn, $DBUSER, $DBPASS)
or die( qq|cannot connect to database $DB| );
return $dbh;
}
| [reply] [d/l] |
What kind of errors/results is this giving you?
update: Ack! I had a great example which was completely wrong, because it was based on a misunderstanding of the ora_fetch() command.
So now I'll simply be a voice in the chorus: consider DBI and DBD::Oracle modules rather than oraperl. The resulting code will be more portable (even if you don't care about it for this script, your skillset is enhanced by this). | [reply] |
the sql satement is valid sql. It is the same thing that
you worte. e1_attrib_type is the name of the table
| [reply] |
You are right. I'm just not used to seeing SQL with embedded \n's or without the ; at the end. sorry.
| [reply] |
Ok I have it working for one line with this code.
@ln = &make_list;
print"<font size=5>Delete Attribute From Database</font>\n";
print"<form method=post action=/cgi-bin/BXJOH27/del_attrib_admin.pl>\n
+";
print"<select size=10 name=\"attrib_lines\">\n";
print"<option>$ln[0] $ln[1] $ln[2] $ln[3]</option>\n";
print"</select>\n";
print"</form>\n";
sub make_list
{
$sql = "select * \n";
$sql .= "from e1_attrib_type \n";
my $cur = ora_open( $lda, $sql );
my @d = ora_fetch( $cur );
ora_close( $cur );
return( @d );
}
But I need the list box to have every line from the database table.
How can I modufy this code to make the list box contain every line and not just
1.
Thanks | [reply] [d/l] |
Having never used oraperl, it's only a guess that ora_fetch() only returns one line of the result set. If there's an ora_fetchall() method, that might work better. Otherwise, you might need to loop:
my @d;
while (my $row = ora_fetch($cur)) {
push @d, $row;
}
| [reply] [d/l] |