PHP分頁 保留查詢條件

來源:互聯網
上載者:User
一個簡單的分頁。可以保留查詢條件。自訂分頁地址<?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><?}?>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.