RE: [htmltmpl] H::T and Table Data
Brought to you by:
samtregar
From: Chris D. <Chris.Davies@ManheimEurope.com> - 2002-08-08 09:50:54
|
A while ago I posted a solution that can defer the decision on the number of columns to the template designer. This may help. See http://bluedot.net/mail/archive/read.php?f=9&i=2353&t=2345 in the mailing list archive for details Chris -- Chris Davies, Manheim Online Tel. 0113 393-2004 Fax. 0870 444-0482. Mobile 07778 199069 -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Roy Rubin Sent: Thursday, August 08, 2002 6:02 AM To: Philip S Tellis; HTML Template Subject: RE: [htmltmpl] H::T and Table Data > > I am writing a script that displays data in a 2-column format. > I am using > > HTML::Pager in order to only display a certain amount of > records per page. > > Given that, what is the best method to loop through the records and > > retrieve, essentially two records per HTML table row. > > I do this all the time. > > <tmpl_loop foo> > <tmpl_if __ODD__><tr></tmpl_if> > <td><tmpl_var foobar></td> > <tmpl_if __LAST__><tmpl_if > __ODD__><td> </td></tmpl_if></tmpl_if> > <tmpl_unless __ODD__></tr></tmpl_if> > </tmpl_loop> > > The first if __ODD__ checks if it's the start of a new row - 1, 3, 5, > etc. > The unless __ODD__ checks if it's the end of the row - after 2, 4, 6, > etc. > The if __LAST__ && __ODD__ checks if it is the last entry in the list, > but not an even entry, meaning there will be one blank entry in the > table. > > This will only work with two columns. More than that isn't possible. > > Philip > Thank you for the comments. I have spent the last few hours developing a solution that seems to work. In my case, it ended up being 4 columns across (4x2) - so I needed a flexible solution. Here it is (Any comments on how to improve it are always welcome): <snip> $sql = qq{SELECT Caption, Thumbnail, ID From News ORDER BY Position ASC}; $sth = $dbh->prepare($sql) or bail_out(); $sth->execute(); $rv = $sth->rows; $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; for (my $x = $offset; $x < $rows + $offset; $x=$x+4) { $newsql = $sql . " LIMIT $x, 4"; $sth = $dbh->prepare($newsql) or bail_out(); $sth->execute() or bail_out(); my @rv; while(($Caption, $Thumbnail, $ID) = $sth->fetchrow_array()){ push @rv, {Caption => $Caption, Thumbnail => $Thumbnail, ID => $ID}; } push @return_array, {NEWSITEM => \@rv}; } $sth->finish() or bail_out(); $dbh->disconnect() or bail_out(); return \@return_array; }; $pager = HTML::Pager->new( query => $co, get_data_callback => $get_data_sub, rows => $rv, page_size => 8, template => $template ); </snip> Roy ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |