header("Content-type: text/html;charset=GBK");//Output encoding to avoid Chinese garbled characters
$page=isset($_GET['page'] )?intval($_GET['page']):1; //This sentence is to get the value of page in page=18. If page does not exist, then the page number is 1.
$ num = 10; // Show 10 data per page
$ db = mysql_connect ("LocalHost", "ROOT", "7529639"); // Create a database connection
MySQL_SELECT_DB ( "cr_download"); //Select the database to operate
/* Divide the database by the number of items displayed on each page, and the remainder is one.
That is to say, 10/3=3.3333=4 If there is a remainder, we must round it up by one.
*/
$result=mysql_query("select * from cr_userinfo");
$total=mysql_num_rows($result); //Query all data
$url ='test.php';//Get the URL of this page
//Calculate the page number
$pagenum=ceil($total/$num); 🎜>$page=min($pagenum,$page);//Get the home page
$prepg=$page-1;//Previous page
$nextpg=($page==$pagenum ? 0 : $page+1);//Next page
$offset=($page-1)*$num; *10=0, the second page is (2-1)*10=10.
//Start paging navigation bar code:
$pagenav="Display page
".($total?($offset+1):0)."-
".min($offset+10,$total)." records, total $total records ";
//If there is only one page, the function will jump out:
if($pagenum<=1) return false;
$pagenav.="
Homepage< /a> ";
if($prepg) $pagenav.=" Previous page " ; else $pagenav.=" Previous page ";
if($nextpg) $pagenav.="
Next page "; else $pagenav.=" Next page ";
$pagenav.="
End Page ";
$pagenav.=" pages, total $pagenum pages";
//If the page number parameter passed in is greater than the total number of pages, then Display error message
If($page>$pagenum){
Echo "Error: Can Not Found The page ".$page;
Exit;
}
$info= mysql_query("select * from cr_userinfo limit $offset,$num"); //Get the data that needs to be displayed for the corresponding page number
While($it=mysql_fetch_array($info)){
Echo $it[' username'];
echo "
";
} echo "
";
echo $pagenav;//Output page navigation
?>
http://www.bkjia.com/PHPjc/317703.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317703.htmlTechArticleToday I was watching Momo’s explanation of pagination. I thought that no one had posted in the original area for a long time, so I expanded Momo’s one by the way. Come on, let’s have a PHP+AJAX paging demonstration. Okay, let’s do it. First, let’s...