Source: http://www.ido321.com/1086.html
Recently, paging was used in the project. Paging is a feature that is often used, so it is encapsulated in a functional form.
//Split-page loading/*** $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)*/functionPaging ($pageType) {Global$pageTotal, $page, $total;if($pageType = = 1) {Echo ' <div id= ' pagenum ' > ';Echo' <ul> '; for($i =0; $i < $pageTotal; $i + +) {if($page = = ($i + 1)) {Echo ' <li><a href= ' blogfriends.php?page= '. ($i + 1).' "class=" selected ">". ($i + 1).' </a></li> '; }Else{Echo ' <li><a href= ' blogfriends.php?page= '. ($i + 1).' > '. ($i + 1).' </a></li> '; } }Echo' </ul> ';Echo' </div> '; }Else if($pageType = = 2) {Echo ' <div id= ' pagetext ' > ';Echo ' <ul> ';Echo ' <li> '. $page.'/'. $pageTotal.' page | </li> ';Echo ' <li> total <strong> '. $total.' </strong> Members | </li> ';//First page if($page = = 1) {Echo ' <li> Home | </li> ';Echo ' <li> prev | </li> '; }Else{//$_server["Script_name"] get the current script name for easy porting //You can also customize constants, constant values and script filenames are consistent Echo ' <li><a href= '. $_server["Script_name"].' > Home </a>| </li> ';Echo ' <li><a href= '. $_server["Script_name"].'? page= '. ($page-1).' > Prev </a>| </li> '; }//Last page if($page = = $pageTotal) {Echo ' <li> next page | </li> ';Echo ' <li> last | </li> '; }Else{Echo ' <li><a href= '. $_server["Script_name"].'? page= '. ($page + 1).' > Next </a>| </li> ';Echo ' <li><a href= '. $_server["Script_name"].'? page= '. ($pageTotal).' > Last </a>| </li> '; }Echo ' </ul> ';Echo ' </div> '; }}
Parameter explanation:
$pageTotal is the total number of pages, $page is the current page, $total is the total amount of data obtained from the database;
For simplicity, all parameters are encapsulated
//Paging parameter sub-assembly/*** $sql An SQL statement that can get the total number of data* $size Show the number of bars per page*/functionPageparam ($sql, $size) {//Set global variables for all 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 '])) {//Specific page$page = $_get[' page '];//Determine if 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{//Initialize display 1th page$page = 1; }//Database clear 0 if($total = = 0) {//Set to 1$pageTotal = 1; }Else{//page total number of pages (in one rounding processing)$pageTotal = Ceil ($total/$pagesize); }//pages greater than total page $total if($page > $pageTotal) {$page = $pageTotal; }//When the page starts with a record$pagestart = ($page-1) * $pagesize;}
Parameter explanation:
$pagestart is when a page starts from a record, $pagesize is the number of records displayed per page
In use, call Pageparam First, and then call paging
/** * First SQL statement to get the total number of data * The Second page shows the number of bars * /Pageparam ( "Select UserID from User ", 2);
<?php //Paging type 1 is the number of page 2 is the text paging paging (2); >
The location of the call is selected according to the situation, and the text is paginated as follows:
<?php //page Type 1 is the number of page 2 is the text paging paging (1);?>
The numbers are paginated as follows:
Style adjusts itself.
Next: Google Maps API shows a small example of the map
PHP Implementation paging: text pagination and digital paging