<? Php
// This example is taken from phpbuilder.com.
// A little Translation
// <Sprming@netease.com>
$ Limit = 20; // number of lines displayed per page
$ Numresults = mysql_query ("select * from TABLE where your conditional here order by WHATEVER"); // replace it with the required SQL statement
$ Numrows = mysql_num_rows ($ numresults );
// Next determine if offset has been passed to script, if not use 0
If (empty ($ offset )){
$ Offset = 1;
}
// Obtain the query result
$ Result = mysql_query ("select id, name, phone ".
"From TABLE where your conditional here ".
"Order by WHATEVER limit $ offset, $ limit ");
// The query result is displayed now.
While ($ data = mysql_fetch_array ($ result )){
// Insert the result and style you want to display here
}
// Display button
If ($ offset! = 1) {// bypass PREV link if offset is 1
$ Prevoffset = $ offset-20;
Print "<a href = \" $ PHP_SELF? Offset = $ prevoffset \ "> previous page </a> \ n ";
}
// Calculate the number of pages
$ Pages = intval ($ numrows/$ limit );
// $ Pages now contains int of pages needed unless there is a remainder from division
If ($ numrows % $ limit ){
// Has remainder so add one page
$ Pages ++;
}
For ($ I = 1; $ I <= $ pages; $ I ++) {// display the page number
$ Newoffset = $ limit * ($ i-1 );
Print "<a href = \" $ PHP_SELF? Offset = $ newoffset \ "> $ I </a> \ n ";
}
// Check to see if last page
If (! ($ Offset/$ limit) ==$ pages) & $ pages! = 1 ){
// Not last page so give NEXT link
$ Newoffset = $ offset + $ limit;
Print "<a href = \" $ PHP_SELF? Offset = $ newoffset \ "> next page </a> <p> \ n ";
}
?>