Share The php paging function module and php paging function module _ PHP Tutorial

Source: Internet
Author: User
Share The php paging function module and the php paging function module. Share The php paging function module. The php paging function module will first paste a picture to see the effect of the code. php $ localhostlocalhost; $ usernameroot; $ passwordroot; $ dbt share the php paging function module, php paging function module

First paste a picture to see the effect

Paste the code.

<? Php $ localhost = "localhost"; $ username = "root"; $ password = "root"; $ db = "test"; // information $ pagesize = 5; $ conn = mysql_connect ($ localhost, $ username, $ password); // link to the database if (! $ Conn) {echo "database link failed ". mysql_error ();} mysql_query ("set names 'utf8'"); // Encode and convert $ db_select = mysql_select_db ($ db ); // select the table // total number of query records $ total_ SQL = "select COUNT (*) from page"; $ total_result = mysql_query ($ total_ SQL); $ total_row_arr = mysql_fetch_row ($ total_result ); $ total_row = $ total_row_arr [0]; // total number of entries // total number of pages $ total = ceil ($ total_row/$ pagesize ); // Current page $ page =@ _ GET ['P']? $ _ GET ['P']: 1; // lower limit of limit $ offset = ($ page-1) * $ pagesize; $ SQL = "select * from page order by id limit {$ offset}, {$ pagesize}"; $ result = mysql_query ($ SQL); echo"

Small module of PHP paging code

"; Echo" "; Echo" "; While ($ row = mysql_fetch_assoc ($ result) {$ id = $ row ['id']; $ name = $ row ['name']; echo" ";} Echo"
ID NAME
". $ Id ." ". $ Name ."
"; // Previous page, next page $ pageprev = $ page-1; if ($ page >$ total) {$ pagenext = $ total ;} else {$ pagenext = $ page + 1;} // Link jump; echo "previous page next"; mysql_free_result ($ result); mysql_close ($ conn);?>

Key points:

1,

$sql = "select * from page order by id limit {$offset},{$pagesize}";

2,

The code is as follows: echo "previous page previous next page ";

These two points are the key points that reflect the paging technology and php Code art ~

The above is all the content shared in this article. I hope you will like it.

Paste a picture to see the effect. php $ localhost = "localhost"; $ username = "root"; $ password = "root "; $ db = "t...

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.