Simple example of data display by page using PHP, and example of php display by PAGE

Source: Internet
Author: User

Simple example of data display by page using PHP, and example of php display by PAGE

Paging is a frequently used function in background management, which facilitates the management of a large amount of data.

The instance code is as follows:

<! DOCTYPE html> 

When there is a large amount of data, the above method cannot be used.

<? Php $ con = mysql_connect ("localhost", "root", ""); mysql_query ("set names utf8"); mysql_select_db ("zhiye", $ con ); $ pageSize = 1; // The number displayed per page $ rowCount = 0; // get $ pageNow = 1 from the database; // page number displayed. // If pageNow exists, the first page is displayed by default. If (! Empty ($ _ GET ['pagenow']) {$ pageNow = $ _ GET ['pagenow'];} $ pageCount = 0; // indicates the total number of pages $ sql1 = "select count (id) from user"; $ res1 = mysql_query ($ sql1); if ($ row1 = mysql_fetch_row ($ res1 )) {$ rowCount = $ row1 [0];} // calculates the total number of pages. ceil takes 1 $ pageCount = ceil ($ rowCount/$ pageSize )); // when using SQL statements, note that values should be assigned to some variables. $ Pre = ($ pageNow-1) * $ pageSize; $ sql2 = "select * from user limit $ pre, $ pageSize"; $ res2 = mysql_query ($ sql2 ); // $ SQL = "select * from user"; // $ res = mysql_query ($ SQL, $ con); while ($ row = mysql_fetch_assoc ($ res2 )) {echo $ row ['user _ name']. "<br>"; echo $ row ['name']. "<br>"; echo $ row ['email ']. "<br>"; echo $ row ['Password']. "<br>"; echo $ row ['tel ']. "<br>";} if ($ pageNow> 1) {$ prePage = $ pageNow-1; echo "< Href = 'userlist. php? PageNow = $ prePage '> pre </a> ";} if ($ pageNow <$ pageCount) {$ nextPage = $ pageNow + 1; echo" <a href = 'userlist. php? PageNow = $ nextPage '> next </a> "; echo" Current page {$ pageNow}/total page {$ pageCount ";} echo "<br/>" ;?> <Form action = "userList. php"> <input type = "text" name = "pageNow"> <input type = "submit" value = "GO"> </form>

The simple example of the above PHP implementation of data paging display is all the content shared by xiaobian. I hope to give you a reference and support for the help house.

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.