一個簡單的分頁。可以保留查詢條件。自訂分頁地址<?phprequire_once("global.php") ;function _PAGEFT($totle, $displaypg = 20, $url = '') { global $page, $firstcount, $pagenav, $_SERVER; $GLOBALS["displaypg"] = $displaypg; if (!$page) $page = 1; if (!$url) { $url = $_SERVER["REQUEST_URI"]; } //URL分析: $parse_url = parse_url($url);//url解析 $url_query = $parse_url["query"]; //單獨取出URL的查詢字串 if ($url_query) { echo $url_query."<br>"; $url_query = ereg_replace("(^|&)page=$page", "", $url_query); $url = str_replace($parse_url["query"], "", $url); if($url_query) { $url.=$url_query."&page"; } else{ $url .= "page"; } } else { $url .= "?page"; } $lastpg = ceil($totle / $displaypg); //最後頁,也是總頁數 $page = min($lastpg, $page); $prepg = $page -1; //上一頁 $nextpg = ($page == $lastpg ? 0 : $page +1); //下一頁 $firstcount = ($page -1) * $displaypg; //開始分頁導航條代碼: $pagenav = "顯示第 <B>" . ($totle ? ($firstcount +1) : 0) . "</B>-<B>" . min($firstcount + $displaypg, $totle) . "</B> 條記錄,共 $totle 條記錄"; //如果只有一頁則跳出函數: if ($lastpg <= 1) return false; $pagenav .= " <a href='$url=1'>首頁</a> "; if ($prepg) $pagenav .= " <a href='$url=$prepg'>前頁</a> "; else $pagenav .= " 前頁 "; if ($nextpg) $pagenav .= " <a href='$url=$nextpg'>後頁</a> "; else $pagenav .= " 後頁 "; $pagenav .= " <a href='$url=$lastpg'>尾頁</a> "; //下拉捷徑清單,迴圈列出所有頁碼: $pagenav .= " 到第 <select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n"; for ($i = 1; $i <= $lastpg; $i++) { if ($i == $page) $pagenav .= "<option value='$i' selected>$i</option>\n"; else $pagenav .= "<option value='$i'>$i</option>\n"; } $pagenav .= "< lect> 頁,共 $lastpg 頁"; }$page=$_GET["page"];$result=$db->query("SELECT * FROM regsip");$total=mysql_num_rows($result);//調用pageft(),每頁顯示10條資訊(使用預設的20時,可以省略此參數),使用本頁URL(預設,所以省略掉)。_PAGEFT($total,5);echo $pagenav; $result=$db->query("SELECT * FROM regsip limit $firstcount,$displaypg "); while($row=mysql_fetch_array($result)){ ?><table width=500 border="1" cellpadding="5" cellspacing="1" bgcolor="#add3ef"> <tr bgcolor="#eff3ff"> <td>姓名:<?=$row[loginname]?> </td> </tr></table><?}?>