I currently have a need to paginate a database query on my website, kind of like search results. I am using HTML::Template so I thought a good module choice to help me with this would be HTML::Page. I am running into a couple of problems though. When I try to use the sample code from the CPAN site, I get the following error:
syntax error at /var/www/fd/entries.pl line 20, near "my " Execution of /var/www/fd/entries.pl aborted due to compilation errors.
Here is the code:
#!/usr/bin/perl use HTML::Pager; use CGI; my $query = CGI->new(); # create a callback subroutine to generate the data to be paged my $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; for (my $x = 0; $x < $rows; $x++) { push(@return_array, [ time() ]); } return \@return_array; } # create a Pager object my $pager = HTML::Pager->new( # required parameters query => $query, get_data_callback => $get_data_sub, rows => 100, page_size => 10, debug => 1, ); # make it go - send the results to the browser. print $pager->output;
Now I know that there is nothing in the code about HTML::Template and sending the output to a .tmpl file, but I was kind of expecting an error relating to that, and not the error that I have listed above. What is wrong? I have googled this too.
Once I do get this to work, how do I display results 1-10 on the first page by default with no user input? Do I make the variables $offset and $rows a default value?
I appreciate everyone's help.In reply to Pagination with in HTML::Template by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |