This should get you going... I have shown you how to do page ranges just for the hell of it.

# http://somesite.com/cgi-bin/display.pl?current_page=12 # display.pl #!/usr/bin/perl -w use strict; use CGI; #use DBI; my $SCRIPT = 'http://somesite.com/cgi-bin/display.pl'; my $RECS_PER_PAGE = 10; my $q = new CGI; print $q->header; #my $dbh = DBI->connect( etc.... ); if ( $q->param('start')) { display_this_db_section( $q->param('start'), $q->param('end'), $q- +>param('current_page') ); } else { my $count = get_record_count(); my $page = $q->param('current_page') || 1; my $html = get_current_page($page); $html .= generate_links($count, $page ); print $html; } exit 0; #### SUBS #### sub display_this_db_section { my ($start, $end, $current_page ) = @_; $current_page ||= $start; my $count = get_record_count; die_nice ( 'Invalid' ) if $start > $count or $start < 1 or $end > $count or $end < 1 or $start > $end or $start > $current_page or $end < $current_page; print "<h3>Here is $current_page of $start-$end<h3>\n"; print "<p>", generate_links( $count, $current_page ) # blah } sub generate_links { my ($count, $current_page ) = @_; my $html = ''; for ( my $start = 1; $start <= $count; $start += $RECS_PER_PAGE ) +{ my $end = $start + $RECS_PER_PAGE -1; $end = $count if $end > $count; $html .= ( $start <= $current_page and $current_page <= $end ) + ? "[$start-$end] " : qq!<a href="$SCRIPT?start=$start&end=$end">[$start-$e +nd]</a> \n!; } return $html; } sub get_current_page { my $page = shift; # validate page, get data, format, return html return "<p>This is the content for page $page<p>\n"; } sub get_record_count { # get count of records, simulate here return 42; } sub die_nice { print shift and exit }

Prints

This is the content for page 1

[1-10] [11-20] [21-30] [31-40] [41-42]

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Page Links... by tachyon
in thread Page Links... by powerhouse

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.