Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

paginator help

by leegold (Novice)
on May 21, 2004 at 05:04 UTC ( #355184=perlquestion: print w/replies, xml ) Need Help??

leegold has asked for the wisdom of the Perl Monks concerning the following question:

For the past couple of days I have been pulling out my hair on how to use a paginator in Perl. I am learning template-toolkit because it seems a lot of paginator modules use the toolkit. So ie. 20 results/page w/back and forward links. What I need is very simple working code - if only I had the simplist of real working code - just a working example. No working examples on the web(?!) I would be grateful again for a simple real life working example - the data file, the Perl file, the template file - wouldn't that be it? Thanks. Lee G. It'd be for a DBI CGI rendering but hey, just a simple hash, array, file, I'll take any working code, then I can riff off of it. Thanks.

Replies are listed 'Best First'.
Re: paginator help
by eric256 (Parson) on May 21, 2004 at 05:11 UTC
    HTML::Paginator Has an example directly on that man page. In general thought pageing is just a matter of knowing where you are in a set, and showing X number of elements after that. If you aren't at the beginning then have a back button that moves you back X places, if you aren't at the end then move ahead X places. If you want to be fancy and have a list of pages then devide the total number of elements by X and make that many links each moving the cursor to the correct place in the set.

    Eric Hodges
Re: paginator help
by matthewb (Curate) on May 21, 2004 at 06:38 UTC

    Template::Plugin::Page is, not surprisingly, a plugin for TT2 that does exactly what you describe. There is a very simple working example on the man page.

      Did you say "working example"? I thought I heard you say "working example". Not a half-baked ditty (that a sub-genius like me can not understand)? I'm there!!! Thanks!
Re: paginator help
by tachyon (Chancellor) on May 21, 2004 at 09:35 UTC
      Thank you for the support. I appreciate it.
Re: paginator help
by geektron (Curate) on May 21, 2004 at 05:40 UTC
    well, it is something you can easily do with 2 DB queries (one using LIMIT and a start/end pair -- or even just a start and calculate the end) passed into the application.

    first query just gets the number of rows, second gets the limit .. and use the results of the first divided by the number of elements per page, and you have the number of pages.

    process that number of pages as needed per templating system. i generate an array of hashrefs to pass into HTML::Template for stuff i've been doing recently. it's been a while since i've used Template::Toolkit.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2020-10-31 23:50 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (291 votes). Check out past polls.