[htmltmpl] nested loops
Brought to you by:
samtregar
From: Kenneth G. <la...@th...> - 2003-09-29 08:47:57
|
hi i have some data that i want to output in three columns, so i'm trying to build a nested loop. This is the perl code: #!/usr/bin/perl -w use CGI; use HTML::Template; use strict; use DBI; my $q = new CGI(); my @rows = (); my @cls = (); my $q1 = "select id,blurb,thumb from pictures"; my $st1 = $dbh->prepare($q1); $st1->execute; my $cl = -1; while (my @r = $st1->fetchrow) { $cl++; my %data; my $pic = '/pics/'.$r[2]; $data{id} = $r[0]; $data{pic} = $pic; $data{blurb} = $r[1]; $cls[$cl] = \%data; if ($cl == 3) { my %rowdata; $rowdata{cols} = \@cls; push (@rows,\%rowdata); @cls = (); $cl = -1; } } my $log = HTML::Template->new ( filename => 'foo.tmpl', path => './tmpl', associate => $q ); $log->param(image => $title, LIST => \@rows); print $q->header, $log->output(); _________________________________________ and this is the relevant part of the template code: <table border="1" cellspacing="0" cellpadding="5"> <TMPL_LOOP NAME = "LIST"> <tr> <TMPL_LOOP NAME = "cols"> <td> <img src="<TMPL_VAR NAME='pic'>"> </td> </TMPL_LOOP> </tr> </TMPL_LOOP> </table> _________________________________ but there is no output kg |