PHP paging code learning example sharing_PHP tutorial

WBOY
Release: 2016-07-13 10:25:00
Original
759 people have browsed it

Copy code The 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 how many rows of data there are in total
$sql1 = "select count(*) from user";
$ret1 = mysql_query($sql1);
$row1 = mysql_fetch_row($ret1);
$tot = $row1[0];

//How many rows of data per page
$length = 5;
//Total number of pages
$totpage = ceil($tot / $length);

//Current page number
$page = @$_GET['p'] ? $_GET['p'] : 1;
//limit lower limit
$offset = ($page - 1) * $length;

echo "

";
echo "

php padding

";
echo "";
echo "";
echo "";
echo "";
echo "< th>PASS";
echo "";

//Display the queried data in a table
$sql2 = "select * from user order by id limit {$offset}, {$length}";
$ret2 = mysql_query($sql2) ;
while ($row2 = mysql_fetch_assoc($ret2)) {
echo "

";
echo "";
     echo "";
}

echo "

IDUSER
{$row2['id']} {$row2['name']}{$row2['pass']}
";

//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>"$sql2 = "select * from user order by id limit {$offset}, {$length}";", the relationship between $offset, $length and the number of pages.

<2>How to obtain the previous page and next page, and the critical point.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825276.htmlTechArticleCopy 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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!