Hey guys i am using perl and trying to pull a list of books from a database and then populate the list in a separate TT2 file. When the list is generated there should be 39 book names. When I do the foreach statement in my tt2 below, the first statement gives me 39 Array(random number) and the second way gives me 39 Hash(random number). How do i get it to display the name in the database?
Perl file:
#!/usr/bin/perl-w
##############################################
use strict;
use Template;
use DBI;
use CGI;
use warnings;
my $user='web';
my $password='nouser';
my $db='bible';
my $dsn = "DBI:mysql:$db";
my $dbh = DBI->connect($dsn, $user, $password) or die $DBI::errstr;
$tt_object = Template->new(
{
INCLUDE_PATH =>
[ '/export/srv/www/vhosts/main/tt2' ]
}
);
$template = '1.tt2';
my($template, $tt_object, $cgi_object, $sample, $vars, $title,$heading,
%where);
my $N_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='N'~;
my $sth=$dbh->prepare($N_query);
$sth->execute;
my $N_booknames=$sth->fetchall_arrayref({});
$vars = {
N_booknames =>$N_booknames,
};
$tt_object->process ( $template, $vars ) || die;
__END__
TT2 file:
[% FOREACH i IN N_booknames %]
<option value="[% i %]">[% N_booknames.$i %]</option>
[% END %]
[% FOREACH i IN N_booknames %]
<option value="[% i %]">[% N_booknames %]</option>
[% END %]