Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
HTML::Template->param expects an array reference of hash references. So you would need to create a structure like this
$myarrayref = [ { NAME => 'Bob' , JOB => 'Programmer'} , { NAME => 'Bill' , JOB => 'Manager'} , ];
and use it like this.
$template->param( EMPLOYEE_INFO => $myarrayref);
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.
# 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();
Once you have the array reference of hash references you can pass this to the param method of HTML::Template like so.
$template->param(EMPLOYEE_INFO => $myarrayref);

In reply to Re: DBI and HTML::Template by Anonymous Monk
in thread DBI and HTML::Template by czarfred

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-08-11 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?