Short answer - This is fairly straight-forward, but you need to shift from using the fetchall_* methods to build the nested <tmpl_loop></tmpl_loop> data structure in a named fashion.

Long answer - The HTML::Template module allows for nesting of <tmpl_loop></tmpl_loop> loop structures within the template file which in turn allows you to "dynamically" resize your output table accordingly. For example, consider the template file below ...

<table> <tmpl_loop name="row"> <tr> <tmpl_loop name="cell"> <td align="left"><tmpl_var name="cell"></td> </tmpl_loop> </tr> </tmpl_loop> </table>

... And the following now tested and working Perl code (updated 2002/03/04) ...

my $sth = $dbh->prepare(qq/ SELECT * FROM table /); $sth->execute; my @row; while (my $row = $sth->fetchrow_arrayref) { my @cell; foreach my $cell ( @{$row} ) { push @cell, { 'cell' => $cell }; } push @row, { 'cell' => \@cell}; } $html->param( 'row' => \@row ); $sth->finish;

In this example, an array-of-array-of-hashes has been built representing the nested loops within the HTML template file - When writing code which builds these data structures, I find it exceptionally useful to call upon Data::Dumper to visualise the data structure during development.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'


In reply to Re: Fetchall_Answer Returns by rob_au
in thread Fetchall_Answer Returns by growlf

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.