If you're pulling against a competant database, use the LIMIT SQL key word to limit your matches to a range. I believe you can specify a starting point and a number of records to retrieve. So, modify your CGI to accept an additional argument or two (say, 'start' and 'number'), and on the page, if there are additional records to retrieve, provide a 'next' link with a 'start' value of start+number. Your SQL statement would then look something like this:
$sth = $dbh->prepare('SELECT ... FROM ... WHERE ... LIMIT ?,?') or die
+ "...";
$sth->execute(..., param('start') || 0, param('number') || 10) or die
+"...";
Make sense?
If your SQL database doesn't let you limit queries like that, have it pull everything into, say, an array, and just deal with an array slice that represents the information you want:
my $start = param('start') || 0;
my $num = param('number') || 10;
@results = $sth->execute(...);
@actual = @results[$start..($start+$num)]; # limit them
my $more_to_do = 1 if defined $results[$start + $num + 1];
my $less_to_do = 1 if $start;
print_previous_link if $less_to_do;
print_results(@actual);
print_next_link if $more_to_do;
|