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


In reply to Re: MySQL / Perl Question by Zaxo
in thread MySQL / Perl Question by Anonymous Monk

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.