Hello Monks,

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.
Thank you.

In reply to Pagination with in HTML::Template by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.