Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Database Data Page

by artist (Parson)
on Jul 10, 2003 at 18:20 UTC ( #273084=perlquestion: print w/ replies, xml ) Need Help??
artist has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks
Here is my code-cut.
my $result = Database->get_results($query); Display->results($result);
and package Display uses HTML::Template to display the $result. It works fine currently. It displays 5000+ records.

Q: How do I use HTML::Pager or another module such that I can display data page by page, may be 100 at a time.

Thank you,
artist

Comment on Database Data Page
Download Code
Re: Database Data Page
by cleverett (Friar) on Jul 11, 2003 at 00:14 UTC
    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!

Re: Database Data Page
by little (Curate) on Jul 11, 2003 at 17:30 UTC

    what about using LIMIT as a native SQL language construct?
    SELECT * FROM tableName LIMIT 0, 10
    or in another way:
    SELECT $whatever and $whomever FROM $sometable LIMIT $minDisplaySetOff, $maxDisplayRowsPerPage
    actually it should read $maxDisplayRowsPerResultSet

    Have a nice day
    All decision is left to your taste

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://273084]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (20)
As of 2014-10-20 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (89 votes), past polls