Sharing a PHP Paging function code, using this function to implement the paging code is very good.
Code, PHP paging functions.
Copy the Code code as follows:
/*
* Created on 2011-07-28
* Author:lkk, Http://lianq.net
* How to use:
Require_once (' mypage.php ');
$result =mysql_query ("SELECT * FROM MyTable", $myconn);
$total =mysql_num_rows ($result); Total information obtained
Pagedivide ($total, 10); Call a paging function
Database operations
$result =mysql_query ("select * FROM MyTable limit $sqlfirst, $shownu", $myconn);
while ($row =mysql_fetch_array ($result)) {
... Your actions
}
Echo $pagecon; Output Paging navigation content
*/
if (!function_exists ("Pagedivide")) {
# $total Total Information
# $SHOWNU Display number, default 20
# $url this page link
function Pagedivide ($total, $shownu =20, $url = ") {
# $page Current Page
# $sqlfirst MySQL Database start item
# $pagecon Page Navigation content
Global $page, $sqlfirst, $pagecon, $_server;
$GLOBALS ["Shownu"]= $shownu;
if (Isset ($_get[' page ')) {
$page =$_get[' page ';
}else $page = 1;
#如果 $url Use the default, which is NULL, assigns a value to this page URL
if (! $url) {$url =$_server["Request_uri"];}
#URL分析
$parse _url=parse_url ($url);
@ $url _query= $parse _url["Query"]; Take out the question mark? After the content
if ($url _query) {
$url _query=preg_replace ("/(&?) (page= $page)/"," ", $url _query);
$url = Str_replace ($parse _url["Query"], $url _query, $url);
if ($url _query) {
$url. = "&page";
}else $url. = "page";
}else $url. = "? page";
#页码计算
$LASTPG =ceil ($total/$SHOWNU); Last page, total pages
$page =min ($LASTPG, $page);
$PREPG = $page-1; Previous page
$NEXTPG = ($page = = $lastpg? 0: $page + 1); Next page
$sqlfirst = ($page-1) * $SHOWNU;
#开始分页导航内容
$pagecon = "Show section". ($total? ($sqlfirst + 1): 0). " -". Min" ($sqlfirst + $shownu, $total). "Records, total $total Records";
if ($lastpg <=1) return false; If only one page jumps out of the
if ($page!=1) $pagecon. = "Home"; else $pagecon. = "Home";
if ($PREPG) $pagecon. = "front page"; else $pagecon. = "front page";
if ($NEXTPG) $pagecon. = "Back Page"; else $pagecon. = "Back Page";
if ($page! = $LASTPG) $pagecon. = "Last"; else $pagecon. = "Last";
#下拉跳转列表, cycle through all page numbers
$pagecon. = "To\ n ", for ($i =1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagecon. ="$i \ n "; else $pagecon. ="$i \ n ";} $pagecon. = "Page, total $lastpg page ";
}
}else die (' Pagedivide () the same name function already exists! ');
?>
http://www.bkjia.com/PHPjc/736859.html www.bkjia.com true http://www.bkjia.com/PHPjc/736859.html techarticle sharing a PHP paging function code, using this function to implement the paging code is very good. Code, PHP paging functions. Copy the code as follows: PHP/* * Created on 2011-07-28 * Author:lkk ...