- Page out
- /**
- * $pageType Paging Type 1 is the number page 2 is the text paging
- * $pagetotal, $page, $total and other data can be passed as parameters, or in paging as global variables (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 '
- A total of '. $total. ' A Member |
';
- First page
- if ($page = = 1)
- {
- Echo '
- Home |
';
- Echo '
- Prev |
';
- }
- Else
- {
- $_server["Script_name"] gets the current script name for easy porting
- You can also customize constants, constant values and script filenames are consistent
- Echo '
- Home |
';
- Echo '
- Prev |
';
- }
- Last page
- if ($page = = $pageTotal)
- {
- Echo '
- Next Page |
';
- Echo '
- End |
';
- }
- Else
- {
- Echo '
- Next Page |
';
- Echo '
- End |
';
- }
- Echo '
';
- Echo ';
- }
- }
Copy CodeParameter interpretation: $pageTotal is the total number of pages, $page is the current page, $total is the total amount of data obtained from the database; 2, the parameters are all encapsulated
- Split-page parameter loading
- /**
- * $sql An SQL statement that can get the total number of data
- * $size show the number of bars per page
- */
- function Pageparam ($sql, $size)
- {
- Set the global variables for all the parameters involved
- $pagestart where a page starts
- $total total number of records $page a page $pageTotal total pages
- Global $pagestart, $pagesize, $total, $page, $pageTotal;
- $pagesize = $size;
- Get Total data
- $total = Mysql_num_rows (Querydb ($sql));
- Error handling, first determine if there is
- if (Isset ($_get[' page '))
- {
- A specific page
- $page = $_get[' page '];
- Determines 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); Rounding to prevent decimals from appearing
- }
- }
- Else
- {
- Initialization shows page 1th
- $page = 1;
- }
- Database zeroing
- if ($total = = 0)
- {
- Set to 1
- $pageTotal = 1;
- }
- Else
- {
- The total number of pages in the page (in-one rounding)
- $pageTotal = Ceil ($total/$pagesize);
- }
- Pages larger than total page $total
- if ($page > $pageTotal)
- {
- $page = $pageTotal;
- }
- When a page starts from a record
- $pagestart = ($page-1) * $pagesize;
- }
Copy CodeParameter interpretation: $pagestart is when a page starts from a record, $pagesize is the number of records displayed per page 3, in use, call Pageparam First, and then call paging
- /**
- * The first SQL statement to get the total number of data
- * The second each page shows the number of bars
- */
- Pageparam ("Select userid from User", 2);
- Paging Type 1 is a number page 2 is a text paging
- Paging (2);
- ?>
Copy Code4, the call location according to the specific circumstances of choice, the text page:
- Paging Type 1 is a number page 2 is a text paging
- Paging (1);
- ?>
Copy Code |