in reply to Re^4: Best way to send records to the browser?
in thread Best way to send records to the browser?
Here you go. This should be close to what you're doing (adjust the column names in the query). Related reading of interest: DBI recipes.
use warnings; use strict; use Template; use DBI; my $dbh = DBI->connect("dbi:mysql:mycow;mysql_read_default_file=$ENV{H +OME}/.my.cnf", undef, undef, { RaiseError => 1 }); my $sth = $dbh->prepare("SELECT id, name, email FROM user LIMIT 3 OFFS +ET 100"); $sth->execute(); my $employees_loh = $sth->fetchall_arrayref({}); my $tt = Template->new(); $tt->process(\*DATA, { users => $employees_loh }) or die $tt->error(), "\n"; __END__ [% FOR user IN users %] <div class="record"> <div class="id">[% user.id %]</div> <div class="name">[% user.name %]</div> <div class="email">[% user.email %]</div> </div> [% END %] -- Output ------------------ <div class="record"> <div class="id">101</div> <div class="name">Actaeonis</div> <div class="email">Accius@sitesviagra.com</div> </div> <div class="record"> <div class="id">102</div> <div class="name">varvang</div> <div class="email">vartang@roliks.com</div> </div> <div class="record"> <div class="id">103</div> <div class="name">JacobHorony</div> <div class="email">jeremilerom@bestbussiness.net</div> </div>
I wasn't trying to disrespect HTML::Template too! It's a fine choice and I understand why some prefer a view without a mini-language on top.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Best way to send records to the browser?
by Perobl (Beadle) on Jun 26, 2010 at 23:07 UTC |