in reply to Fetchall_Answer Returns

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'