Copy CodeThe code is as follows:
Header ("Content-type:text/html;charset=utf-8");
Database connection
$conn = mysql_connect ("localhost", "root", "111") or Die ("Not connnected:". Mysql_error ());
mysql_select_db ("Test", $conn);
mysql_query ("Set names UTF8");
Query the total number of rows of data
$sql 1 = "SELECT count (*) from user";
$ret 1 = mysql_query ($sql 1);
$row 1 = mysql_fetch_row ($ret 1);
$tot = $row 1[0];
How many rows of data per page
$length = 5;
Total pages
$totpage = Ceil ($tot/$length);
Current page
$page = @$_get[' P ']? $_get[' P ']: 1;
Limit limit
$offset = ($page-1) * $LENGTH;
echo "
";
echo "
PHP padding
";
echo "
Display the queried data in a table
$sql 2 = "SELECT * from the user order by ID limit {$offset}, {$length}";
$ret 2 = mysql_query ($sql 2);
while ($row 2 = MYSQL_FETCH_ASSOC ($ret 2)) {
echo "
echo "
"; echo "
"; echo "
| ID | "; echo "
USER | "; echo "
PASS | "; echo "
";
"; echo "
| {$row 2[' id '} |
{$row 2[' name '} |
{$row 2[' pass '} | "; echo "
"; }
";
Previous page and next page
$prevpage = $page-1;
if ($page >= $totpage) {
$nextpage = $totpage;
} else {
$nextpage = $page + 1;
}
Jump
echo "
Previous Page | next page
";
echo " ";
Core points:
<1> "$sql 2 =" SELECT * from the user order by ID limit {$offset}, {$length} ";", the relationship between $offset, $length, and number of pages.
<2> How to get the previous and next pages, and the tipping point.
http://www.bkjia.com/PHPjc/825276.html www.bkjia.com true http://www.bkjia.com/PHPjc/825276.html techarticle Copy the code as follows: PHP header ("Content-type:text/html;charset=utf-8");//database connection $conn = mysql_connect ("localhost", "root", "111") or Die ("Not connnected:". mysql ...