in reply to Outputing data from mySQL query into format for use with HTML::Template

Assuming the fieldnames in your template are the same as the fieldnames in your database, you can do:

$sth->execute( $SearchCrit ); my @results = (); while ( my $row = $sth->fetchrow_hashref ) { push @results, \%{ $row }; } $tmpl->param( stuff => \@results ); ...

This isn't the most efficient but it's the easiest to understand. (And for small datasets like putting tables of data in a web page, you probably won't notice the difference.)

Note that if you try a shortcut and push $row directly into @results you'll get the same row over and over.

Chris
M-x auto-bs-mode

  • Comment on Re: Outputing data from mySQL query into format for use with HTML::Template
  • Download Code

Replies are listed 'Best First'.
Re: Re: Outputing data from mySQL query into format for use with HTML::Template
by sutch (Curate) on Mar 10, 2001 at 05:52 UTC
    The two responses before mine do a nice job of answering you question--and I've handled this task in a similar manner.

    I have since started using Template Toolkit, available on CPAN with additional information available at http://www.tt2.org. I find this template module much more flexible. As a matter of fact, you may pass the database handle directly to the template, saving memory and processing.