The advice you already got answers your question, but you may not need to know how many pages you get. You will if you want to index them all on each page, but you can just try a page number check if you get results.
You can also get mysql to do more of the work for you. The LIMIT clause in sql can take placeholders (at least in the mysql driver). Here is code which searches a zipcode database in chunks of 30 for towns starting and ending with 'A':
my $limited = $dbi->prepare('select Zipcode, Zipname from zips
where Zipname like ? order by 1 limit
+ ?,?');
my ( $pagelines, $page) = ( 30, 0);
while ($limited->execute( 'A%A', $page++ * $pagelines, $pagelines)
&& $limited->rows) {
my @rec = $limited->fetchrow_array;
printf "%2d records starting with: %05d %s$/",
$limited->rows,
$rec[0], $rec[1];
}
=pod
Output is:
30 records starting with: 04330 AUGUSTA
30 records starting with: 22301 ALEXANDRIA
30 records starting with: 30316 ATLANTA
30 records starting with: 33920 ALVA
30 records starting with: 47001 AURORA
30 records starting with: 54720 ALTOONA
30 records starting with: 61414 ALTONA
30 records starting with: 67010 AUGUSTA
30 records starting with: 72611 ALPENA
30 records starting with: 80018 AURORA
6 records starting with: 97103 ASTORIA
The number of pages can be obtained from:
$pages = int(($limited->execute( 'A%A', 0, -1), $limited->rows)/$pagel
+ines)
+ ($limited->rows % $pagelines | 0 ? 1 : 0);
This is a ceil() function, it acts like int but rounds up.
=cut
Notice that we don't need to know how many there are, we just check if the return has zero rows. You'll need to keep track of what page the user just saw, that is saving state in a session. There are lots of ways to do that, but a form value with the current page number would work fine.
After Compline, Zaxo |