Php paging code learning example sharing _ PHP Tutorial

Source: Internet
Author: User
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" ";Echo" ";Echo" ";Echo" "; ";Echo" ";Echo" ";}
IDUSERPASS
{$ Row2 ['id']} {$ Row2 ['name']} {$ Row2 ['pass']}
";

// 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.