PHP paging function Sample code sharing

Source: Internet
Author: User
Tags min

  This article mainly introduces the PHP paging function sample code, need friends can refer to the following

Share a case of PHP paging function code, using this function to implement the pagination code is very good.   Code, PHP paging function.   Code as follows: <?php/* Created on 2011-07-28 * Author:lkk, Http://lianq.net * Use method: require_once (' mypage.php '); $result =mysql_query ("SELECT * FROM MyTable", $myconn); $total =mysql_num_rows ($result);    //Total information obtained pagedivide ($total, 10);    //Call paging function  //Database operations $result =mysql_query ("select * FROM MyTable limit $sqlfirst, $shownu", $myconn); while ($row =mysql_fetch_array ($result)) {... Your action} echo $pagecon;    //Output Paging navigation content */  if (!function_exists ("Pagedivide")) {# $total     Information Total # $shownu     Show Number, default # $url     page link function pagedivide ($total, $shownu =20, $url = ') {  # $page current page number # $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 to this page URL if (! $url) {$url =$_server["Request_uri"];}   #URL分析 _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, $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); The next page $sqlfirst = ($page-1) * $SHOWNU;   #开始分页导航内容 $pagecon = "show First". ($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   if ($page!=1) $pagecon. = "<a href= ' $url =1 ' > Home </a>"; else $pagecon. = "Home page"; if ($PREPG) $pagecon. = "<a href= ' $url = $prepg ' > front page </a>"; else $pagecon. = "front page"; if ($NEXTPG) $pagecon. = "<a href= ' $url = $nextpg ' > Back page </a>"; else $pagecon. = "Back Page"; if ($page!= $lastpg) $pagecon. = "<a href=" $url =$lastpg ' > Last </a> '; else $pagecon. = "Last";   #下拉跳转列表, loop 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 () a function with the same name already exists! '); ?>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.