PHP paging function sample code sharing_PHP tutorial

WBOY
Release: 2016-07-13 10:36:50
Original
831 people have browsed it

Share an example of PHP paging function code. It is very good to use this function to implement paging code.

Code, php paging function.

Copy code The code is as follows:

/*
* Created on 2011-07 -28
* Author: LKK, http://lianq.net
* Usage:
require_once('mypage.php');
$result=mysql_query("select * from mytable" , $myconn);
$total=mysql_num_rows($result); //Get the total number of information
pageDivide($total,10); //Call the paging function

//Database operation
$result=mysql_query("select * from mytable limit $sqlfirst,$shownu", $myconn);
while($row=mysql_fetch_array($result)){
...Your operation
}
echo $pagecon; //Output paging navigation content
*/

if(!function_exists("pageDivide")){
#$total Total number of information
#$shownu Display quantity, default 20
#$url Link to this page
function pageDivide($total ,$shownu=20,$url=''){

#$page current page number
#$sqlfirst mysql database starting item
#$pagecon Paging navigation content
global $page,$sqlfirst,$pagecon,$_SERVER;
$GLOBALS[ "shownu"]=$shownu;

if(isset($_GET['page'])){
$page=$_GET['page'];
}else $page=1;

#If $url uses the default value, which is an empty value, the value is assigned to the URL of this page
if(!$url){ $url=$_SERVER["REQUEST_URI"];}

#URL analysis
$parse_url=parse_url($url);
@$url_query=$parse_url["query"]; //Extract the content after the question mark?
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";

#Page number calculation
$lastpg=ceil($total/$shownu); //Last page, total number of pages
$page=min($lastpg,$page);
$prepg= $page-1; //Previous page
$nextpg=($page==$lastpg ? 0 : $page+1); //Next page
$sqlfirst=($page-1)* $shownu;

#Start paging navigation content
$pagecon = "Show the ".($total?($sqlfirst+1):0)."-".min($sqlfirst+$shownu,$total)." Records, a total of $total records";
if($lastpg<=1) return false; //If there is only one page, jump out

if($page!=1) $pagecon .=" Homepage "; else $pagecon .="Homepage";
if ($prepg) $pagecon .=" Previous page "; else $pagecon .=" Previous page";
if($nextpg) $pagecon .=" Last page "; else $pagecon .=" Next page";
if($page!=$lastpg) $pagecon.=" Last page "; else $pagecon .=" Last page";

# Drop down jump list, loop through all page numbers
$pagecon .=" Go to page of $lastpg";

}
}else die('pageDivide() function with the same name already exists!');
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736859.htmlTechArticleSharing an example of PHP paging function code, it is very good to use this function to implement paging code. Code, php paging function. Copy the code The code is as follows: ?php /* * Created on 2011-07-28 * Author : LKK...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template