I won't claim this is the best way to do it, but it's a way to do it. Update: I recommend you look at one of the other solutions.

Query the database, and put all the data in an array (I would probably make each element of the array a struct which contains all the data on a particular record). Then you can simply keep track of your location in the array (1, 49, 99, etc) and make a previous link which passes the current location -50 (if applicable) and a next link which passes the current location +50 (again, if this doesn't exceed the limits of the array). Run a loop that prints out all array entries between your current starting point and 50 more (or the end of the array, whichever comes first). Of course you need to make sure that the information in the array is available to the instance or program that prints it.

One possible problem with this approach is that your array could contain outdated information if the database is changed frequently. You could re-query the database, but that could mess up the order, unless you are ordering by a sequencial key.


In reply to Re: What's the best way to get the first n rows (kudra: get the whole result) by kudra
in thread What's the best way to get the first n rows, the second n rows... from a database? 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.