Re: [htmltmpl] [Question] H::T and DBI => stuffing query info into <TMPL_LOOP>'s
Brought to you by:
samtregar
From: petersm <pe...@ve...> - 2004-04-13 15:12:01
|
C Hagstrom wrote: > I'm hoping for some conceptual help here.... > I have tried to find references to my question without > success ( the list-archive link appears not to be working). > > > I can get the results to print directly with this code: > > $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' ORDER > BY Location"); > $sth->execute (); > while ( my $hash_ref = $sth->fetchrow_hashref ) { > print "ID: $hash_ref->{'ID'} -- Name: > $hash_ref->{'Name'} (etc....) <br>\n"; > } > > > Now that I am an H::T convert, I'm looking for guidance > on how best to handle the database output so I can > take advantage of the <TMPL_LOOP> feature in H::T you can use something like this to get the structure from DBI $sth = $dbh->prepare("SELECT FirstName, LastName FROM Person WHERE ..."); #this will get an array of hashrefs my $result = $sth->fetchall_arrayref({}); then you would put that structure into your template like so... my $tmpl->HTML::Template->new(..); $tmpl->param('Person_Loop' => $result); and then your template could look like this <TMPL_LOOP Person_Loop> Hello, My name is <TMPL_VAR FirstName> <TMPL_VAR LastName>.<br /> </TMPL_LOOP> Does that help? Michael Peters Venzia |