Home > Backend Development > PHP Tutorial > PHP paging code learning example sharing_PHP tutorial

PHP paging code learning example sharing_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:25:00
Original
853 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template