faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

100 of 129 people (78%) answered Yes
Recently 6 of 10 people (60%) answered Yes


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..
Simple Limit:
LIMIT 1 - Select first result only.
LIMIT 10 - Select first 10 results.
Paged Limit:
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:
<a href="somescript.php?position=21&numresults=20">Previous</a>
To do a next page add numresults to position:
<a href="somescript.php?position=41&numresults=20">Next</a>