[htmltmpl] resultset Paging and Row limitation
Brought to you by:
samtregar
From: Massoud K. <mk...@ca...> - 2007-02-04 21:01:06
|
Hi, I am new to the Html-template and perl. How can I show the resultset to the web page which Shows 10 records per page and also page numbers on the bottom of the table? This is my perl codes; #!perl use DBI; use strict; use CGI qw/:standard/; use HTML::Template; # open the html template my $template = HTML::Template->new(filename => 'temp.tmpl'); my $username = "mm"; my $password = "kk"; my $dsn = "DBI:mysql:database:localhost"; my $dbh = DBI->connect($dsn,$username,$password) or die "Cannot connect to database: $DBI::errstr"; my $search = param('search'); my $sql ="SELECT * FROM database where name like '$search%' or last like '$search%'"; my $sth = $dbh->prepare($sql); $sth->execute() or die "Cannot execute sth: $DBI::errstr"; # a reference to the array of results my $tbl_ary_ref = $sth->fetchall_arrayref({}); # cleanup $sth->finish; $dbh->disconnect; # assign the reference to the results to a h::t var called results $template->param(results => $tbl_ary_ref); print "Content-Type: text/html\n\n", $template->output(); my 'temp.tmpl' is: <!-- loop over results --> <tmpl_loop name=results> <tr> <td align="center"><tmpl_var Name=name></a></td> <td align="center"><tmpl_var name=last></a></td> </tr> </tmpl_loop> Many thanks, MK |