Home  >  Article  >  Backend Development  >  PHP paging function_PHP tutorial

PHP paging function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:55:37979browse

//Establish database connection
$link = mysql_connect("localhost", "root", "wyh7ye");
; // Get the current page number
mysql_select_db("test",$link);
if(isset($_GET[page]))...{
$page = intval($_GET[page]);
}
else...{
$page = 1;
}
//Quantity per page
$page_size =4;
//Get the total data amount
$sql = "select * from user";
$result = mysql_query($sql,$link);
while($row = mysql_fetch_array($result))...{
$i=$i+1;
}
$amount = $i;
// Calculate how many pages there are in total
if( $amount )...{
if( $amount < $page_size )...{ $page_count = 1; } //If the total data amount is less than $PageSize, then there is only one page
if( $amount % $page_size )...{ //Get the remainder of the total data amount divided by the number of pages
$page_count = (int)($amount / $page_size) + 1; //If there is a remainder, the number of pages is equal to the total data amount divided by the number of each page, rounded up and plus one
}else...{
$page_count = $amount / $page_size ; //If there is no remainder, the number of pages is equal to the total data amount divided by the number of pages
}
}
else...{
$page_count = 0;
}
// Get data and return the result in two-dimensional array format
if( $amount )...{
$sql = "select * from user order by id desc limit ". ($page-1)*$page_size .",$page_size";
$result =mysql_query($sql,$link);
while ($row =mysql_fetch_array($result))...{
?>









}
}
// Page turning link
$page_string ="";
if( $page == 1 )...{
$page_string.="First page|Previous page|";
}
else...{
$page_string.= "First page|href=?page=".($page-1).">Previous page|";
}
if( ($page == $page_count) || ($page_count == 0) )...{
$page_string.="Next page|Last page";
}
else...{
$page_string.= "Next page|Last page";
}
echo $page_string;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318270.htmlTechArticle?php //Establish a database connection $link=mysql_connect(localhost,root,wyh7ye); ;//Get the current Number of pages mysql_select_db(test,$link); if(isset($_GET[page]))...{ $page=intval($_GET[page]); } e...
Statement:
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