Leroy <le***@thevelvetbox.net> wrote in message
news:Ij8td.149059$V41.97686@attbi_s52...
I really need some help with showing pages of results from queries in
say like groups of 20 with next and previous buttons or links. I'm
having a lot of trouble figuring out the logic of such a script. I know
someone has written this script before. Please help.
I'm sure there's a more elegant way of doing this but here is a simple, easy
way:
1: Setup your table with an autoincrementing integer field (we'll call this
field recID)
2: Have your SQL statement read something like:
"SELECT * FROM tblName LIMIT 20 ORDER BY recID"
3: Your "next" link should have the number of the last record displayed. So
it might look something like:
"<a href="shownextrecords.php?lastdisplayed=20">Next Records</a>
4: When the "next" link is clicked, query the database the same as before
EXCEPT add a "WHERE recID > $lastdisplayed" to your query so that the
records will be the next 20 records in the database. Keep your ORDER BY and
LIMIT statements the same.
You might want to make check each time you do a query and make sure that the
set being displayed isn't the last set to be displayed. If it is, you
obviously don't wan't to display a "next" link on that set.
Like I said, it's real easy and there are probaby much easier and more
elegant ways to do this. But that's just my take on it. Others here might do
it differently.
Good Luck,
Anthony