PHP functions implement paging effect, php text paging and numeric paging
- // Pagination
- /**
- * $ PageType paging Type 1: numeric paging 2: text paging
- * You can pass $ pageTotal, $ page, $ total, and other data as parameters, or use paging as a global variable (recommended)
- */
- Function paging ($ pageType)
- {
- Global $ pageTotal, $ page, $ total;
- If ($ pageType = 1)
- {
- Echo'
';
- Echo'
';
- For ($ I = 0; $ I <$ pageTotal; $ I ++)
- {
- If ($ page = ($ I + 1 ))
- {
- Echo'
- '. ($ I + 1 ).'
';
- }
- Else
- {
- Echo'
- '. ($ I + 1 ).'
';
- }
- }
- Echo'
';
- Echo'';
-
- }
- Else if ($ pageType = 2)
- {
- Echo'
';
- Echo'
';
- Echo'
- '. $ Page.'/'. $ pageTotal.' page |
';
- Echo'
- Total'. $ Total .'Members |
';
- // Page 1
- If ($ page = 1)
- {
- Echo'
- Homepage |
';
- Echo'
- Previous Page |
';
- }
- Else
- {
- // $ _ SERVER ["SCRIPT_NAME"] get the name of the current script for ease of transplantation
- // You can also customize constants. the constant value is consistent with the script file name.
- Echo'
- Homepage |
';
- Echo'
- Previous Page |
';
- }
- // Last Page
- If ($ page = $ pageTotal)
- {
- Echo'
- Next Page |
';
- Echo'
- Last page |
';
- }
- Else
- {
- Echo'
- Next Page |
';
- Echo'
- Last page |
';
- }
- Echo'
';
- Echo'';
- }
- }
-
Parameter explanation: $ pageTotal indicates the total number of pages, $ page indicates the current page, and $ total indicates the total number of data retrieved from the database; 2. encapsulate all parameters
- // Split paging parameters
- /**
- * $ SQL: an SQL statement that obtains the total number of data.
- * $ Size number of entries displayed on each page
- */
- Function pageParam ($ SQL, $ size)
- {
- // Set global variables for all involved parameters
- // $ Where does pagestart start from?
- // $ Total number of records $ page a page $ total number of pageTotal pages
- Global $ pagestart, $ pagesize, $ total, $ page, $ pageTotal;
- $ Pagesize = $ size;
- // Obtain the total number of data items
- $ Total = mysql_num_rows (queryDB ($ SQL ));
-
- // Handle the error. First, determine whether the error exists.
- If (isset ($ _ GET ['Page'])
- {
- // Specific page
- $ Page = $ _ GET ['Page'];
- // Determine whether it is empty (0 is empty)/less than 0/whether it is a number
- If (empty ($ page) | $ page <0 |! Is_numeric ($ page ))
- {
- $ Page = 1;
- }
- Else
- {
- $ Page = intval ($ page); // integer to prevent decimal occurrence
- }
-
- }
- Else
- {
- // Page 1st is displayed during initialization.
- $ Page = 1;
- }
-
- // Reset the database
- If ($ total = 0)
- {
- // Set to 1
- $ PageTotal = 1;
- }
- Else
- {
- // The total number of pages (one-to-one integer)
- $ PageTotal = ceil ($ total/$ pagesize );
- }
-
- // The page number is greater than the total page number $ total
- If ($ page> $ pageTotal)
- {
- $ Page = $ pageTotal;
- }
- // When the page starts from a record
- $ Pagestart = ($ page-1) * $ pagesize;
- }
-
Parameter explanation: $ pagestart indicates the number of records displayed on each page starting from a certain record. $ pagesize indicates the number of records displayed on each page. 3. in use, call pageParam before calling paging.
- /**
- * The first SQL statement that can obtain the total number of data
- * Number of Entries displayed on the second page
- */
- PageParam ("select userid from user", 2 );
-
- // Page Type 1: digital page 2: text page
- Paging (2 );
- ?>
4. select the call location based on the actual situation. text paging:
- // Page Type 1: digital page 2: text page
- Paging (1 );
- ?>
|