Php paging code learning example sharing. Copy the code as follows :? Phpheader (content-type: texthtml; charsetutf-8); database connection $ connmysql_connect (localhost, root, 111) ordie (notconnnected:. mysql
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 the total number of rows of data
$ 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;
// Lower limit of limit
$ Offset = ($ page-1) * $ length;
Echo"
";
Echo "php padding ";
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"
| ID | ";Echo"
USER | ";Echo"
PASS | ";Echo"
";
";Echo"
| {$ Row2 ['id']} |
{$ Row2 ['name']} |
{$ Row2 ['pass']} | ";Echo"
";}
";
// Previous and next pages
$ 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} ";", relationship between $ offset, $ length, and page number.
<2> obtain the previous and next pages, as well as the critical point.
The http://www.bkjia.com/PHPjc/825276.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825276.htmlTechArticle code is as follows :? Php header ("content-type: text/html; charset = utf-8"); // connection to the database $ conn = mysql_connect ("localhost", "root", "111 ") or die ("not connnected :". mysql...