Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found