Login   Register  
PHP Classes
elePHPant
Icontem

File: OptionPager.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of comet  >  Option Pager  >  OptionPager.php  >  Download  
File: OptionPager.php
Role: Class source
Content type: text/plain
Description: Paging the web
Class: Option Pager
Generate links to browse listings split in pages
Author: By
Last change:
Date: 5 years ago
Size: 3,674 bytes
 

Contents

Class file image Download
<?php
    
/*
        Author : Dao Hoang Qui    
        Email  : dhoangqui@gmail.com or daohoangqui@yahoo.com    
        Date   :  05/09/2009
        Function : Paging in 3 ways : "Prev|Next" and "<< < 1 2 3 > >>"  and "<< < 1 2 3 > >> Sum : 9999"
    */
    
class Pager
    
{
        
/*
            Function  : find the started number of specific page
            Paremeter : $limit is the row number in one page.
            Return    : interger to determinate start position for LIMIT start,length in sql statement 
        */
        
function findStart($limit)
        {
            if(!isset(
$_GET["page"]) || ($_GET["page"]=="1"))            
            {
                
$start 0;
                
$_GET["page"] = 1;
            }
            else
                
$start = ($_GET["page"]-1) * $limit;
            return 
$start;
        }
        
        
/*
            Function  : sum pages from the number records in database and the number rows in the page
            Paremeter : $limit is the same above ; $count is the number of records in database.
            Return    : interger to determinate the total pages to display.
        */
        
function findPages($count,$limit)
        {
            return ((
$count%$limit)==0) ? $count/$limit floor($count/$limit)+1;
        }
        
        
//Paging in Prev|Next
        
function nextPrev($curPage,$pages)
        {
            
$nextPrev "";
            if ((
$curPage-1)<=0)
                
$nextPrev "Trang trước";
            else 
                
$nextPrev "<a href='".$_SERVER["PHP_SELF"]."?page=".($curPage-1)."'>Trang trước </a>";
            
$nextPrev .= " | ";
            if ((
$curPage+1)>$pages)
                
$nextPrev .= "Trang sau";
            else 
                
$nextPrev .= "<a href='".$_SERVER["PHP_SELF"]."?page=".($curPage+1)."'>Trang sau </a>";
            return 
$nextPrev;
        }
        
        
//Paging in << < 1 2 3 > >>
        
function pageList($curPage,$pages)
        {
            
$pageList "";
            
            
// << <
            
if (($curPage-1)<=0)
                
$pageList "";
            else 
            {
                
$pageList "<a href='".$_SERVER['PHP_SELF']."?page=1"."'><< </a>";
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".($curPage-1)."'> <</a>";
            }
            
            
// 1 2 3
            
for ($page=$page<=$pages $page++)
                if(
$page == $curPage)
                    
$pageList .= " "."<a href='".$_SERVER['PHP_SELF']."?page=".$page."' style='color:RED'>".$page."</a>"." ";
                else     
                    
$pageList .= " "."<a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a>"." ";
                    
            
// > >>        
            
if (($curPage+1)>$pages)
                
$pageList .= "";
            else 
            {
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".($curPage+1)."'>> </a>";
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".$pages."'>>></a>";
            }        
            
//return
            
return $pageList;
        }
        
        
//Paging in << < 1 2 3 > >>  Sum : 100
        
function etcPageList($curPage,$pages,$limit)
        {
            
$pageList "";
            
            
// << <
            
if (($curPage-1)<=0)
                
$pageList "";
            else 
            {
                
$pageList "<a href='".$_SERVER['PHP_SELF']."?page=1"."'><< </a>";
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".($curPage-1)."'> <</a>";
            }
            
            
// 1 2 3 
            
if ($pages $limit)
                
$limit $pages;
                
            
$limit = (($limit+$curPage-1)<$pages) ? $limit+$curPage-$pages;

            for (
$page=$curPage $page<=$limit $page++)
                if(
$page == $curPage)
                    
$pageList .= " "."<a href='".$_SERVER['PHP_SELF']."?page=".$page."' style='color:RED'>".$page."</a>"." ";
                else     
                    
$pageList .= " "."<a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a>"." ";
                    
            
// > >>                    
            
if (($curPage+1)>$pages)
                
$pageList .= "";
            else 
            {
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".($curPage+1)."'>> </a>";
                
$pageList .= "<a href='".$_SERVER['PHP_SELF']."?page=".$pages."'>>></a>";
            }
            
            
//Sum : 
            
$pageList .= " Tổng cộng : ".$pages;
            
            
//return
            
return $pageList;
        }
    }
?>