/*
requirements, build a test database, build a test table inside,
Just enter the data as long as the ID field is available.
As the level is limited, error is unavoidable.
*/
$conn = mysql_connect ("localhost", "root", "");
$maxnum = 2; Number of 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 '); Total number of data set data
$totalpages = Ceil ($totalRows 1/$maxnum);//Calculate the total number of pages, Ceil () is the upper function
if (!isset ($_get[' page ')) | |!intval ($_get[' page ') | | $_get[' page '] > $totalpages) $page = 1; Default handling of 3 types of errors
When the URL parameter page does not exist, when the page is not 10 binary, the page is larger than the number of pages, the default is 1
else $page = $_get[' page ');
$startnum = ($page-1) * $MAXNUM; Starting with the data set $startnum, note that the dataset starts at 0
$query = "SELECT * FROM Test LIMIT $startnum, $maxnum";//Select the data that meets the requirements start with $startnum data and choose $maxnum Line
$result = mysql_query ($query, $conn) or Die (Mysql_error ());
$row = Mysql_fetch_assoc ($result);
?>
<title>pagination Example</title>
| pagination Example |
do {?>
|
There's no record.
Mysql_free_result ($result 1);
Mysql_free_result ($result);
?>
http://www.bkjia.com/PHPjc/318081.html www.bkjia.com true http://www.bkjia.com/PHPjc/318081.html techarticle ? PHP/* requirements, build a test database, build a test table inside, as long as the ID field, enter the data can be. As the level is limited, error is unavoidable. */ $...