PHP Implementation paging: text pagination and digital paging,
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 '';Echo'
';
for ($i =0; $i < $pageTotal; $i + +) {
if($page = = ($i + 1)) {
echo
'
- . ($i + 1). ' "class=" selected ">". ($i + 1). '
'
; }
Else {
echo
'
- . ($i + 1). ' >'. ($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"] get the current script name for easy porting
//You can also customize constants, constant values and script filenames are consistent
Echo
'
- . $_server["Script_name"]. ' > Home |
';
Echo
'
- . $_server["Script_name"]. '? page= '. ($page-1). ' > Prev |
'; }
//Last page
if($page = = $pageTotal) {
Echo
'
- Next Page |
';
Echo
'
- End |
'; }
Else{
Echo
'
- . $_server["Script_name"]. '? page= '. ($page + 1). ' > Next |
';
Echo
'
- . $_server["Script_name"]. '? page= '. ($pageTotal). ' > Last |
'; }
Echo
'
';Echo ''; }}
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);
//Paging type 1 is the number 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:
//Paging type 1 is the number 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
http://www.bkjia.com/PHPjc/897990.html www.bkjia.com true http://www.bkjia.com/PHPjc/897990.html techarticle PHP Implementation paging: Text paging and digital paging, Source: http://www.ido321.com/1086.html Recently, paging is used in the project. Paging is a feature that is often used, so ...