php对mysql查询结果进行分页
时间:2021-07-01 10:21:17
帮助过:27人阅读
- function pageSplit($startPos, $rowsPerPage = '', $totalRows = '' )
- {
-
- $numPages = $totalRows / $rowsPerPage ;
- $tenthPages = $rowsPerPage * 10 ;
- If($startPos >= $tenthPages )
- {
- $back10Position = $startPos - $tenthPages ;
- $pageString .= '<< ';
- }
-
- if($startPos >= $rowsPerPage)
- {
- $backPosition = $startPos - $rowsPerPage;
- $pageString .= 'Back ';
- }
-
- if($totalRows != '')
- {
- $page = ceil($startPos / $rowsPerPage);
- $pageCount = $page + $numPages;
-
- $PageNo = ceil($startPos / $rowsPerPage ) ;
- // echo ' Page No ' . $PageNo ;
- for($i = 1,$pgCnt=1; $page <= $pageCount; $i = $i + $rowsPerPage)
- {
- if ( $PageNo == $pgCnt )
- {
- $pageString .= ' '.$pgCnt.' ';
- $pgCnt++;
- }
- elseif ($i < $totalRows)
- {
- $pageString .= ' '.$pgCnt.' ';
- $pgCnt++;
- };
-
- $page++;
- };
- }
-
- $nextPosition = $startPos + $rowsPerPage;
-
- if($totalRows == '')
- {
- $pageString .= 'Next ';
- }
- elseif($startPos < $totalRows )
- {
- If ( $nextPosition < $totalRows )
- {
- $pageString .= 'Next ';
- }
- }
-
- if($startPos < $totalRows )
- {
- $next10Position = $startPos + $tenthPages ;
-
- If($next10Position < $totalRows )
- {
- $next10Position = $startPos + $tenthPages ;
- $pageString .= ' >>';
- }
- }
- return $pageString;
- }
- ?>
|
分页, 查询结果, php