<?php
/*
requirements, build a test database, build a test table inside it,
As long as the ID field, enter the data is OK ...
Because the level is limited, inevitable error.
*/
$conn = mysql_connect ("localhost", "root", "");
$maxnum = 2; Display record bars per page
mysql_select_db ("Test", $conn);
$query 1 = "Select COUNT (*) as totalrows from Test";
$result 1 = mysql_query ($query 1, $conn) or Die (Mysql_error ());
$row 1 = mysql_fetch_assoc ($result 1);
$totalRows 1 = $row 1[' totalrows ']; Data set data total number of bars
$totalpages = Ceil ($totalRows 1/$maxnum);//Calculate the total number of pagination, ceil () is the UP function
if (!isset ($_get[' page ')) | | |!intval ($_get[' page ') | | $_get[' page '] > $totalpages) $page = 1; Default handling of 3 types of errors
When a page is not 10 in number when the URL parameter page does not exist, the default is 1 when the page is greater than the page can be divided
else $page = $_get[' page '];
$startnum = ($page-1) * $MAXNUM; Starting from the dataset $startnum, note that the dataset starts at 0
$query = "SELECT * FROM Test LIMIT $startnum, $maxnum"//Select the data that meets the requirements from the $startnum data, choose $maxnum Line
$result = mysql_query ($query, $conn) or Die (Mysql_error ());
$row = Mysql_fetch_assoc ($result);
?>
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service