-
- //Paging
- /**
- * $pageType paging type 1 is numeric paging 2 is text paging
- * You can pass $pageTotal, $page, $total and other data as parameters, or use it as a global variable in paging (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 '
- There are'.$total.'members|
';
- // First page
- if($page == 1)
- {
- echo '
- Homepage|
';
- echo '
- Previous page|
- }
- else
- {
- // $_SERVER["SCRIPT_NAME"] gets the current script name to facilitate transplantation
- // You can also customize constants, the constant values are 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 a>|
$pageTotal is the total number of pages, $page is the current page, $total is the total number of data obtained from the database;
-
- 2. Encapsulate all parameters
//Paging parameter packaging/*** $sql can obtain a sql statement of the total number of data * $size displays the number of items on each page */ function pageParam($sql,$size) { //Set all involved parameters to global variables // $pagestart someone Where does a page start // $total total number of records $page a certain page $pageTotal total number of pages global $pagestart,$pagesize,$total,$page,$pageTotal;- $pagesize = $size;
- // Get the total number of data
- $total = mysql_num_rows(queryDB($sql));
-
- // Error handling, first determine whether it exists
- if(isset($_GET['page']))
- {
- // A 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); //Rounding to prevent decimals from appearing
- }
-
- }
- else
- {
- //Initialization Display page 1
- $page = 1;
- }
-
- // Clear database
- if($total == 0)
- {
- // Set to 1
- $pageTotal = 1;
- }
- else
- {
- / / The total number of pages in paging (further rounded up)
- $pageTotal = ceil($total / $pagesize);
- }
-
- // The number of pages is greater than the total page number $total
- if($page > $pageTotal)
- {
- $page = $pageTotal;
- }
- // When the page starts from a certain record
- $pagestart = ($page - 1) * $pagesize;
- }
-
-
-
- Copy code
-
-
- Parameter explanation:
$pagestart is when the page starts from a certain record, $pagesize is the number of records displayed on each page
-
- 3. During use, call pageParam first, then call paging
-
-
-
-
/** * The first one can get a sql statement of the total number of data * The second one can display the number of items on each page */ pageParam("select userid from user",2); //Paging type 1 is numeric paging 2 is text paging paging(2 ); ?>
-
- Copy code
-
-
- 4. The calling location is selected according to the specific situation, and the text is paginated:
-
-
-
-
-
- //Paging type 1 is digital paging 2 is text paging
paging(1); ?>Copy code
|