Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Outputing data from mySQL query into format for use with HTML::Template

by lachoy (Parson)
on Mar 10, 2001 at 03:07 UTC ( #63394=note: print w/ replies, xml ) Need Help??


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
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://63394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-12-21 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (100 votes), past polls