PHP introductory learning knowledge point 2 PHP simple paging process and principle_PHP tutorial

WBOY
Release: 2016-07-21 15:27:03
Original
919 people have browsed it

require '../inc/conn.php';
?>

//Initial parameter setting
$pagesize=5 ; //Page size
$pagenum=1; //The default is the first page


//Step 1: Get the current page
if($_GET){
if($_GET['pagenum']){
$pagenum=$_GET['pagenum'];
}
}
//Step 2: Get the content of the current page List

$sql="Select * From message limit ".($pagenum-1)*$pagesize.",$pagesize ";
$result=mysql_query($sql);

while(($row=mysql_fetch_array($result))==true){
echo '


'.$row["title"].'';
}

//Step 3: Get the number of records
$sql="Select id From message";
$result=mysql_query($sql);
$rownum=mysql_num_rows($result );

//Step 4: Count the number of pages
if(($rownum%$pagesize)==0){
$pagecount=$rownum/$pagesize;
}else{
$pagecount=(int)($rownum/$pagesize);
}

//Step 5: Get the paging link
$url=$_SERVER[" REQUEST_URI"];
$url=parse_url($url);
$url=$url["path"];

//Step 6: Output pagination link

if($pagenum==1){
echo "[First page] [Previous page]";
}else{
echo "[First page] [Previous page]";
}


if($pagecount==$pagenum){
echo "[next page] [last page]";
}else{
echo " [Next page] [Last page]";
}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323833.htmlTechArticle?php require '../inc/conn.php'; ? ?php //Initial parameter setting $pagesize =5; //Paging size $pagenum=1; //Default is the first page //Step one: Get the current page if($_GET){ if($_GET...
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