in reply to DBI and HTML::Template
HTML::Template->param expects an array reference of hash references. So you would need to create a structure like this
and use it like this.$myarrayref = [ { NAME => 'Bob' , JOB => 'Programmer'} , { NAME => 'Bill' , JOB => 'Manager'} , ];
To do this using DBI you would want to do something like the following. First fetch each row as a hash reference then push each one of these onto a array reference. Note: you will need to dereference the array reference hence the @$myarrayref.$template->param( EMPLOYEE_INFO => $myarrayref);
Once you have the array reference of hash references you can pass this to the param method of HTML::Template like so.# Create statement handle $sth = $dbh->prepare($somesql); # execute statement handle $sth->execute(); # loop through rows while ($hashref = $sth->fethrow_hashref()) { push @$myarrayref , $hashref; } # clean up statement handle $sth->finish();
$template->param(EMPLOYEE_INFO => $myarrayref);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: DBI and HTML::Template
by chipmunk (Parson) on Nov 22, 2001 at 10:04 UTC |
In Section
Seekers of Perl Wisdom