Code, PHP paging functions.
<?php/** Created on 2011-07-28* Author:lkk, http://lianq.net* method of Use: require_once (' mypage.php '); $result =mysql_query ("SELECT * FROM MyTable", $myconn); $total =mysql_num_rows ($result); Total information obtained pagedivide ($total, 10); Call the paging function//database Operation $result=mysql_query ("SELECT * FROM MyTable limit $sqlfirst, $shownu", $myconn) and while ($row =mysql_fetch_ Array ($result)) {... Your operation}echo $pagecon; Output paging navigation content */if (!function_exists ("Pagedivide")) {# $total total number of messages # $shownu displayed, default 20# $url this page link function pagedivide ($tot Al, $shownu =20, $url = ') {# $page current page www.jbxue.com# $sqlfirst MySQL database start Item # $PAGECON pager content Global $page, $sqlfirst, $ Pagecon,$_server, $GLOBALS ["Shownu"]= $shownu, if (isset ($_get[' page])) {$page =$_get[' page '];} else $page =1; #如果 $url Use the default, or null value, to assign the value to this page Urlif (! $url) {$url =$_server["Request_uri"];} #URL分析 $parse _url=parse_url ($url); @ $url _query= $parse _url["Query"]; Remove 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, $urlif ($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; Prev $nextpg= ($page = = $lastpg? 0: $page + 1); Next $sqlfirst= ($page-1) * $SHOWNU; #开始分页导航内容 $pagecon = "Show section". ($total? ($sqlfirst + 1): 0). " -". Min" ($sqlfirst + $shownu, $total). "Records, total <B> $total </B> Records"; if ($lastpg <=1) return false; If only one page jumps out of the IF ($page!=1) $pagecon. = "<a href= ' $url =1 ' > Home </a>"; else $pagecon. = "First page"; if ($PREPG) $pagecon. = "<a href= ' $url = $prepg ' > Front </a>"; else $pagecon. = "front page", if ($NEXTPG) $pagecon. = "<a href= ' $url = $nextpg ' > Back </a>"; else $pagecon. = "Back Page"; if ($page! = $LASTPG) $pagecon. = "<a href= ' $url = $lastpg ' > Last </a>"; else $pagecon. = "Last"; #下拉跳转列表, cycle through all page numbers $pagecon. = "to <select name= ' topage ' size= ' 1 ' onchange= ' window.location=\" $ Url=\ "+this.value ' >\n", for ($i =1; $i <= $lastpg; $i + +) {if ($i = = $page) $pagecon. = "<option value= ' $i ' selected >$I</option>\n "; else $pagecon. =" <option value= ' $i ' > $i </option>\n ";} $pagecon. = "</select> page, total $lastpg page";}} Else Die (' pagedivide () the same name function already exists! ');? >
Articles you may be interested in:
Entry-level PHP simple page pagination code
PHP pagination Code details (with example)
A simple example of PHP page pagination code
PHP Paging class with a variety of paging methods
A handy PHP paging class
Example of a simple PHP page-out code
A useful PHP page-out class
A fast and easy-to-use PHP paging class
PHP paging function sample code, PHP page code implementation method