//本例子摘自phpbuilder.com
//稍加翻譯
//
$limit=20; // 每頁顯示的行數
$numresults=MySQL_query("select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER");//換成你所需要的sql語句
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
// 得到查詢結果
$result=mysql_query("select id,name,phone ".
"from TABLE where YOUR CONDITIONAL HERE ".
"order by WHATEVER limit $offset,$limit");
// 現在顯示查詢結果
while ($data=mysql_fetch_array($result)) {
// 在這裡插入您要顯示的結果以及樣式
}
// 顯示按鈕
if ($offset!=1) { // bypass PREV link if offset is 1
$prevoffset=$offset-20;
print "上一頁 \n";
}
// 計算頁面數
$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++) { // 顯示頁數
$newoffset=$limit*($i-1);
print "$i \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "下一頁
\n";
}
?>