php对mysql查询结果进行分页

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
<?php
   function pageSplit($startPos, $rowsPerPage = '', $totalRows = '' )
        {
 
            $numPages = $totalRows / $rowsPerPage ;
            $tenthPages = $rowsPerPage * 10 ;
            If($startPos >= $tenthPages )
            {
                $back10Position = $startPos - $tenthPages ;
                $pageString .= '<a href="'.$PHP_SELF.'?startPos='.$back10Position .'&perPageDisplay='.$rowsPerPage.'" title="Previous 10 Pages"><font color="red"><< </font></a>  ';
            }
 
            if($startPos >= $rowsPerPage)
            {
                $backPosition = $startPos - $rowsPerPage;
                $pageString .= '<a href="'.$PHP_SELF.'?startPos='.$backPosition.'&perPageDisplay='.$rowsPerPage.'" title="Previous Page"><font color="blue">Back</a></font> ';
            }
                  
            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 .= ' <a href="'.$PHP_SELF.'?startPos='.$i.'&perPageDisplay='.$rowsPerPage.'" title="Page '.$pgCnt.'""><font color="red"><b>'.$pgCnt.'</b></font></a> ';
                            $pgCnt++;
                        }
                        elseif ($i < $totalRows)
                        {
                            $pageString .= ' <a href="'.$PHP_SELF.'?startPos='.$i.'&perPageDisplay='.$rowsPerPage.'" title="Page '. $pgCnt.'"">'.$pgCnt.'</a> ';
                            $pgCnt++;
                        };
                          
                        $page++;
                    };
            }
 
            $nextPosition = $startPos + $rowsPerPage;
 
            if($totalRows == '')
            {
                $pageString .= '<a href="'.$PHP_SELF.'?startPos='.$nextPosition.'&perPageDisplay='.$rowsPerPage.'" title="Next Page"><font color="blue" >Next </font></a> ';
            }
            elseif($startPos < $totalRows )
            {
                If ( $nextPosition < $totalRows )
                {
                    $pageString .= '<a href="'.$PHP_SELF.'?startPos='.$nextPosition.'&perPageDisplay='.$rowsPerPage.'" title="Next Page"><font color="blue" title="Next Page">Next </font></a>  ';
                }
            }
 
            if($startPos < $totalRows )
            {
                $next10Position = $startPos + $tenthPages ;
 
                If($next10Position < $totalRows )
                {
                    $next10Position = $startPos + $tenthPages ;
                    $pageString .= '<a href="'.$PHP_SELF.'?startPos='.$next10Position .'&perPageDisplay='.$rowsPerPage.'" title="Next 10 Pages"><font color="red"> >></font></a>';
                }
            }
                return $pageString;
        }
?>

标签: isp

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:scrapy在采集网页时使用随机user-agent的方法

下一篇:php动态处理图片后输出显示