[thelist] PHP Previous Next Navigation

jyee jyee at vt.edu
Mon Jun 3 16:03:01 CDT 2002

I myself would still use MySQL to generate the results, but if you're sure
that you want to do this, then I would suggest using the session handling
functions in PHP to persist your array across pages, as it would be much
better than encoding a thousand records in a form and submitting it via GET or

To use the functions, you need to register the variable that you want to use,
such as


, on every page that requires the records.  Afterwards, you can do a simple
assignment and fill up the array:

$Records = array();

while ($Row = mysql_fetch_row($Result))
  $Records[] = $Row[0];

On every page afterwards, $Records will be automatically loaded as a global
variable and is ready for use, so if you wanted records 2010 through 2020,
then you would simply do

$Begin = 2010;
$End = $Begin + 10

for ($i = $Begin; $i < $End;  $i++)
  // Output records

where you can embed $Begin as a value in your next or previous links.

The documentation for the session handling functions are at


Good luck with the project, and feel free to contact me if you have any code
questions.  I use session handling on my website to store login and timeout
information, and it's been a very convenient way of not having to query my
database on every page.

Jackson Yee
jyee at vt.edu

----- Original Message -----
From: "Jay Blanchard" <jay.blanchard at niicommunications.com>
To: <thelist at lists.evolt.org>
Sent: Monday, June 03, 2002 15:22
Subject: RE: [thelist] PHP Previous Next Navigation

> Simon,
> [snip]...stuff about MySQL LIMIT...[/snip]
> Thank you for your information. I am aware of and have used LIMIT for many
> queries in MySQL, but there is a problem here that I probably have not been
> clear enough about. These 3000-5000 records exist in a table that has
> millions of records. So for each query with LIMIT MySQL has to traverse all
> of the records right up until it receives the limit amounts back The further
> into the table you go, the worse the delay. The array, if I built one from
> the desired records, would take up less memeory space than most front pages
> on web sites (under 30k), making it rather quick on subsequent "pages". I
> know how easy it is to do this with LIMIT and I wish that I could take
> advantage of it. But I am afraid that speed is the largest issue at this
> point.

More information about the thelist mailing list