In your code you write a subroutine that HTML::Pager calls to get the data, and this is called a "callback function".

In your example it is this:

# 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, [ $row ]); } return \@return_array; }

Now this is just the stub function frrm the example in the documentation. You don't want that to return a few numbers here, but real data from your database.

So you have to change your callback function:

my $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; # Prepare SQL query: my $sth = $dbi->prepare("Your SQL here that fetches the data from + $offset to $offset+$rows"); $sth->execute($offset, $rows); while (my $array_ref = $sth->fetchrow_arrayref){ push @return_array, $array_ref; } return \@return_array; }

The only thing that's left for you now is to figure out your SQL (a small hint: use placeholders as explained in the DBI documentation).


In reply to Re^3: HTML Pager by moritz
in thread HTML Pager by JimJx

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.