php mysql查询结果分页的简单示例

前端之家收集整理的这篇文章主要介绍了php mysql查询结果分页的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了PHP对mySQL查询结果进行分页 ,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

/**
 * mySQL查询结果分页
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/
   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; 
        } 


/***   代码来自编程之家 jb51.cc(jb51.cc)   ***/
原文链接:https://www.f2er.com/php/528865.html

猜你在找的PHP相关文章