Database Reference
In-Depth Information
• One style of paged display presents only “previous page” and “next page” links. To
do this, you must know whether any rows precede or follow those you display in
the current page.
• Another paging style displays a link for each available page. This enables the user
to jump directly to any page, not just the previous or next page. To present this kind
of navigation, you must know the total number of rows in the result set and the
number of rows per page, so that you can determine how many pages there are.
Paged displays with previous-page and next-page links
The following script, state_pager1.pl , presents rows from the states table in a paged
display that includes navigation links only to the previous and next pages. For a given
page, determine the required links as follows:
• A “previous page” link is required if there are rows in the result set preceding those
shown in the current page. If the current page starts at row one, there are no such
rows.
• A “next page” link is required if there are rows in the result set following those
shown in the current page. You can determine this by issuing a SELECT COUNT(*)
statement to see how many rows the statement matches in total. Another method
is to select one more row than you need. For example, if you display 10 rows at a
time, try to select 11 rows. If you get 11, there is a next page. If you get 10 or less,
there isn't. state_pager1.pl uses the latter approach.
To determine its current position in the result set and how many rows to display,
state_pager1.pl looks for start and per_page input parameters. When you first invoke
the script, these parameters aren't present, so they're initialized to 1 and 10, respectively.
Thereafter, the script generates “previous page” and “next page” links to itself that in‐
clude the proper parameter values in the URLs for selecting the previous or next sections
of the result set:
#!/usr/bin/perl
# state_pager1.pl: paged display of states, with prev-page/next-page links
use strict ;
use warnings ;
use CGI qw(:standard escape escapeHTML) ;
use Cookbook ;
my $title = "Paged U.S. State List" ;
my $page = header ()
. start_html ( - title => $title )
. h3 ( $title );
Search WWH ::




Custom Search