There's major issues with HTML::Pager I see up front: it wants the whole data set up front, and it uses CGI.pm, not quite the thing when you have HTML::Template, IMO.

Since retrieving the entire data set every time through is grossly inefficient, you likely will end up doing one or both of two things: retrieving just the rows you need or caching the results someplace.

Many dialects of SQL will let you specify the rows you need. For instance Mysql has a LIMIT clause:

SELECT * FROM bannerlog.log LIMIT 100, 100;

which says return only the rows starting at the 101st row and going 100 rows from there.

If we were saving state using HTML form variables and using CGI::Request to fetch form parameters (using mod_perl, I'd use Apache::Request) our code would then end up something like:

use CGI::Request; my $req = new CGI::Request; my $rows_per_page = 100; my ($first_row, $command) = map { $req->param($_) } qw/first_row command/; if ($command eq 'previous_page') { $first_row -= $rows_per_page; $first_row = 0 if $first_row < 0; } elsif ($command eq 'next_page') { $first_row += $rows_per_page; } my $result = Database->get_results($query, $first_row); Display->results($result, $first_row);

good luck!


In reply to Re: Database Data Page by cleverett
in thread Database Data Page by artist

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.