Where can I find a php script to show mysql db results 20 at a time, with Next and Previous options?
Aug 28th, 2000 12:57
andrew stott, Ian Thomas, Jason Taylor, Rhyan Allen, Ben Udall,
If you want a script to help you administer a MySQL database, including
these options, then try phpMyAdmin, avaliable from
If you want to build these functions into a PHP script of your own, then
this is also quite simple - You use LIMIT in your SELECT query..
LIMIT 1 - Select first result only.
LIMIT 10 - Select first 10 results.
An extension to LIMIT allows you to set a start position..
LIMIT 1,10 - Retrieve rows 1 to 10.
LIMIT 11,10 - Retrieve rows 11 to 20.
LIMIT 21,10 - Retrieve rows 21 to 30.
So your query should look something like this:
SELECT * FROM tablename ORDER BY somefield LIMIT $position, $numresults
Assuming a current start position of 21, and 20 results per page your
next and previous links would take the form:
To do a next page add numresults to position: