The code for PHP to read mysql database data and implement paging instances is as follows: & lt ;? Php & nbsp; // Connect to database & nbsp; $ dbmysql_connect (localhost, root, root); & nbsp; & nbsp; mysql_select_db (gaoge, $ db) PHP reads mysql database data and implements the following code for paging instance:
-
- // Connect to the database
- $ Db = mysql_connect ("localhost", "root", "root ");
- Mysql_select_db ("gaoge", $ db );
- // Set the number of records displayed on each page
- $ Pagesize = 3;
-
- // Obtain the total number of records and calculate the total number of pages
- $ Res = mysql_query ("select count (*) from image", $ db );
- $ Myrow = mysql_fetch_array ($ res );
- // $ Myrow [o] indicates the sum of the total number of records in the database
- $ Numrows = $ myrow [0];
- // Echo "total num is :";
- // Echo $ numrows;
- // Echo
;
- // Calculate the total number of pages
- $ Pages = intval ($ numrows/$ pagesize );
-
- If ($ numrows % $ pagesize)
- $ Pages;
- // Echo "total pages is :";
- // Echo $ pages;
- // Echo
;
- // Determine whether the page number is set or not. if not, the page number is defined as the homepage.
-
- If (isset ($ _ GET [page]) {
- // Echo "page exist ";
- $ Page = $ _ GET [page];
- // Echo "enter if ";
- }
- Else {
- // Echo "page not exist ";
- $ Page = 1;
- }
-
- // Echo "page is :";
- // Echo $ page;
- // Echo
;
- // Calculate the record offset
- $ Offset = $ pagesize * ($ page-1 );
- // Echo "offset is :";
- Echo $ offset;
- // Retrieve records
- $ Res = mysql_query ("select * from image order by id desc limit $ offset, $ pagesize", $ db );
- // Display records cyclically
- If ($ myrow = mysql_fetch_array ($ res ))
- {
- $ I = 0;
- ?>
-
-
-
-
- $ I;
- ?>
-
-
-
-
-
- "/>
-
-
- While ($ myrow = mysql_fetch_array ($ res ));
- Echo"
- Do {
- }
ID |
Image name |
Uploaded person name |
Upload time |
Image Effects |
";
- }
- // Display the total number of pages
- Echo "total". $ pages. "page (". $ page. "/". $ pages .")
";
- // Display the number of pages
- For ($ I = 1; $ I <= $ pages; $ I)
- Echo "page". $ I ";
- // Echo "page is :";
- // Echo "$ page ";
-
- // Echo"
";
- // Display to page number
- Echo "";
- Echo "";
- ?>