Php paging function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php paging function .? Php * requires that you create a test database and create a test table in it. you only need the id field and enter the data .. Due to the limited level, errors are inevitable .. * $ /*
Requirement: create a test database and create a test table in it.
You only need to enter the id field ..
Due to the limited level, errors are inevitable ..
*/
$ Conn = mysql_connect ("localhost", "root ","");

$ Maxnum = 2; // number of records per page

Mysql_select_db ("test", $ conn );
$ Query1 = "select count (*) AS totalrows FROM test ";
$ Result1 = mysql_query ($ query1, $ conn) or die (mysql_error ());
$ Row1 = mysql_fetch_assoc ($ result1 );
$ TotalRows1 = $ row1 ['totalrows']; // The total number of data entries in the dataset.
$ Totalpages = ceil ($ totalRows1/$ maxnum); // calculates the total number of pages that can be viewed. ceil () is the preceding function.

If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ totalpages) $ page = 1; // Default processing of three types of errors
// When the url parameter page does not exist and the page number is not in decimal order, the default value is 1 when the page is larger than the number of split pages.
Else $ page =$ _ GET ['Page'];

$ Startnum = ($ page-1) * $ maxnum; // This parameter is obtained from entry $ startnum of the dataset. Note that the dataset starts from 0.

$ Query = "SELECT * FROM test LIMIT $ startnum, $ maxnum"; // SELECT the $ maxnum row starting FROM $ startnum
$ Result = mysql_query ($ query, $ conn) or die (mysql_error ());
$ Row = mysql_fetch_assoc ($ result );

?>



Paging example

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.