PHP implements simple data display by page, and php displays instances by page. PHP provides a simple example of data display by page. php displays instances by page in background management, which facilitates management of large amounts of data. The example code is as follows: PHP provides a simple example for displaying data by page, and php displays instances 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:
User list<? 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 ); while ($ row = mysql_fetch_assoc ($ res2) {echo $ row ['User _ name']."
"; Echo $ row ['name']."
"; Echo $ row ['email ']."
"; Echo $ row ['password']."
"; Echo $ row ['tel']."
";}For ($ I = 1; $ I <=$ pageCount; $ I ++) {echo" $ I ";}?>
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']."
"; Echo $ row ['name']."
"; Echo $ row ['email ']."
"; Echo $ row ['password']."
"; Echo $ row ['tel']."
";} If ($ pageNow> 1) {$ prePage = $ pageNow-1; echo" pre ";} if ($ pageNow <$ pageCount) {$ nextPage = $ pageNow + 1; echo "next"; echo "current page {$ pageNow}/total {$ pageCount} pages";} echo"
";?>
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.
Paging is a frequently used function in the background management, which facilitates the management of a large amount of data. The instance code is as follows :...