-
-
/* - * mysql paging function code
- * edit: bbs.it-home.org
- *
- */
- function page($page,$total,$ phpfile,$pagesize=10,$pagelen=7){
- $pagecode = '';//Define variables to store the HTML generated by paging
- $page = intval($page);//Avoid non-numeric page numbers
- $total = intval($total);//Ensure that the total record value type is correct
- if(!$total) return array();//If the total number of records is zero, return an empty array
- $pages = ceil($total/$pagesize);/ /Calculate total paging
- //Process page number legality
- if($page<1) $page = 1;
- if($page>$pages) $page = $pages;
- //Calculate query offset
- $offset = $pagesize*($page-1);
- //Calculation of page number range
- $init = 1;//Starting page number
- $max = $pages;//Ending page number
- $pagelen = ($pagelen%2 )?$pagelen:$pagelen+1;//Number of page numbers
- $pageoffset = ($pagelen-1)/2;//Offset to the left and right of page number
//Generate html
- $pagecode='";
- return array('pagecode'=>$pagecode ,'sqllimit'=>' limit '.$offset.','.$pagesize);
- }
- ?>
-
Copy code
2, added page number jump text frame
-
- $phpfile = 'index.php';//Page file name
- $page= isset($_GET['page'])?$_GET['page']:1; //Default page number
- $db = mysql_connect('localhost','test','test'); //Link database
- mysql_select_db('test',$db); //Select database
- $counts = mysql_num_rows(mysql_query( 'select `id` from `test`',$db));//Get the total number of required data
- $sql='select `id`,`title` from `test`';//Define query statement SQL
- $getpageinfo = page($page,$counts,$phpfile);//Call the function to generate paging HTML and SQL LIMIT clause
- $sql.=$getpageinfo['sqllimit'];//Combine the complete SQL statement
- $data = $row = array();//Initialize the array
- $result = mysql_query($sql,$db);//Get the result set
- //Load the data into the $data array
- while($row = mysql_fetch_array( $result)){
- $data[]=$row;
- }
- ?>
- echo $getpageinfo['pagecode'];//Display pagination html code
- ?>
Copy Code
3, this paging query css style sheet file used in the code.
Recommended reading:
- php and ajax no refresh paging code
- php article paging implementation code
- php limit page turning (pagination) code
- PHP paging class with multiple paging methods
- PHP pagination code for previous page and next page
- PHP paging code for the first ten pages and the next ten pages
- Example of simple php pagination code
- A good php pagination code
- A paging function: Previous page Next page
- A useful php paging class
- php long article pagination code
- A practical php paging class
- Fast php paging class
|