Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Pagination Example #2 Jump to:  
Category: >> PHP Code >> Pagination Example #2 Bookmark and Share

<< lastnext >>

Snippet Name: Pagination Example #2

Description: A well thought out pagination function. Easy to modify and/or expand.

Also see:
» Pagination Example #1

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

Paginating the mySQL data
 
<?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; 
        } 
?>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 160 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?