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

Hello perl friends,
I have a lil problem on my hand.. i have to display a page footer like so Page 1|2|3 Next now the tricky parts are the following situtation .. if the total number of pages is 3 it should as Page 1|2|3 with no Next.... and if that total number of pages are 5 the first footer would be like this Page 1|2|3 Next .. and when u click on next is should show Previous 4|5 and so on and so fourth, also the previous page should take you back to the appropriate pages ... I am give the Total number of pages and the current page ... can anyone help me out with this thank you

Replies are listed 'Best First'.
Re: help on a lil problem here
by artist (Parson) on Jun 28, 2003 at 15:43 UTC
Re: help on a lil problem here
by benn (Vicar) on Jun 29, 2003 at 12:38 UTC
    This sounds suspiciously like homework, so no code will be forthcoming...but it also sounds like you can describe the problem well enough to analyse it like a programmer, so writing your own should be easy.

    Have a think about your inputs and outputs. (It might help the maths to treat your pages as "0|1|2", "3|4|5" etc., then simply add 1 before printing.)

    • Q: Which page numbers do I want to print? A: The block of 3 that contains $current_page. That's something to do with "$start = 3 * int($current_page / 3))" isn't it? (In fact, we could replace "3" with "$pager_size" - then it'd work with any number...).
    • Q: When do I stop printing page numbers? A: When ($offset > $pager_size) or ($pagenum > $num_pages). (Or '>=' or '==', depending on how you write your loop.) Easy.
    • Q: Do I want a 'Next' link? A: Only if int($current_page/$pager_size) is smaller than int($num_pages/$pager_size).
    • Q: Do I want a 'Previous' link? A: Only if int($current_page/$pager_size) > 0
    ...etc. Get these questions clear in your head, and you'll be pumping out code in no time.

    Cheers, Ben.