TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-25-2010, 08:41 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default need help on pagination class.

the problem with the class is that if i want to display 30 records at a time and i have 60 total records the pagination divs that shows the page numbers only shows page #1 and not page #2. i have tried to figure out how to fix it but i have given up. any help would greatly be apreciated.

this is how i call attributes to the class.
PHP Code:
$paginate = new Pagination;
$paginate->pageName "index.php";  //sets the page to use
$paginate->perPage 10//show num of records per page
$paginate->adjacents 3//current page adjacent to 
$paginate->sql "select * from tbl_products"//the main query
$query $db->query($paginate->getData());

while(
$row mysql_fetch_object($query)) {
  print 
$row->pName."<br/>";
}
    
    
$paginate->showPagination(); //shows the pagination div 


here is the class.

PHP Code:
include_once("class.db.php");

class 
Pagination 
{
        
    var 
$param;
    var 
$perPage;
    var 
$adjacents;
    var 
$start;
    var 
$sql;
    var 
$pageName;
        
        
     function 
__construct() 
    {
        
$this->db = new  MysqlDB;
        
$this->db->connect();
     }
        
    function 
setParam() 
    {
                    
        if(isset(
$_GET['page']) && is_numeric($_GET['page']) && ($_GET['page'] > 0)) 
        {
            
$this->param $_GET['page'];
        } 
        
        else 
        {
            
$this->param 1;
        }
    }
        
                
        function 
setIndex()
        {
            
$this->setParam();
            return 
$this->start = ($this->param $this->perPage) - $this->perPage;
        }
        
        function 
showPagination($param1=null,$param2=null,$param3=null
        {
            
$qRows $this->db->query($this->sql);
            
$numRows $this->db->num_rows($qRows);
            
$numOfPages ceil($numRows $this->perPage);
            
$param $this->param;
            
$pageName $this->pageName;
            
$string "";
            
            
//set pagination parameters.
            
if($param1 != null
            {
                if(isset(
$_GET[$param1])) 
                {
                    
$param1Value $_GET[$param1];
                    
$string .= "&".$param1."=".$param1Value;
                }
            }
            
            
            if(
$param2 != null
            {
                if(isset(
$_GET[$param2])) 
                {
                    
$param2Value $_GET[$param2];
                    
$string .= "&".$param2."=".$param2Value;
                }
            }
            
            
            if(
$param3 != null
            {
                if(isset(
$_GET[$param3])) 
                {
                    
$param3Value $_GET[$param3];
                    
$string .= "&".$param3."=".$param3Value;
                }
            }
            
        
    
            
            print 
"<div class='pagination'>";

            print 
"<a href='$this->pageName?page=1$string' class='previous-off'> First </a>";
            
            
            
// ----------------------------------------------------------------------------        
                // PRINT ALL PAGES TO THE LEFT //
                
if(($param $this->adjacents) > 1
                {
                    print 
"<span>...</span>";

                    
$lowerLimit $param $this->adjacents;

                    
//print all on left side.
                    
for($i $lowerLimit$i$param$i++) 
                    {
                        print 
"<a href='$pageName?page=$param = $i$string'> $i </a>";
                    }

                    }  
                    
                    else 
                    {

                        
//print all numbers between current page and  first page.

                        
for($i 1$i $param$i++) 
                        {
                            print 
"<a href='$pageName?page=$i$string'> $i </a>";
                        }
                    }
            
// ----------------------------------------------------------------------------
            
            
            
            //print current page
            
if(($param != 0) && ($param != $numOfPages)) 
            {
                print 
"<span class='current'>$param</span>";
            }
            
            
            
            
            
// ----------------------------------------------------------------------------            
                        //PRINT ALL PAGES TO THE RIGHT
                
if(($param $this->adjacents) < $numOfPages
                {

                    
$upperLimit $param $this->adjacents;

                    for(
$i=($param 1); $i<=$upperLimit$i++) 
                    {
                        print 
"<a href='$pageName?page=$i$string'> $i </a>";
                    }
                        print 
"<span>...</span>";
                    } 
                    else 
                    {

                        
//print all page numbers if out of padded range

                        
for($i = ($param 1); $i<$numOfPages$i++ ) 
                        {
                            print 
"<a href='$pageName?page=$i$string'> $i </a>";
                        }

                    }
            
            
// ----------------------------------------------------------------------------
    
            
$lastPage $numOfPages 1;
            print 
"<a class='next' href='$pageName?page=$lastPage$string'> Last </li>";
    
            print 
"</div>";
        }
        
        
        
        
        
        function 
getData() 
        {
            
$query $this->sql;
            
$this->start $this->setIndex();
            return 
"$query LIMIT $this->start$this->perPage";
        }
        
        
        
        function 
errors() 
        {
            
$query $this->sql;
            print 
"$query LIMIT $this->start$this->perPage"."<br/>";
            print 
"this->start ".$this->start."<br/>";
            print 
"this->param ".$this->param."<br/>";
            print 
"this->perPage ".$this->perPage."<br/>";
            print 
"this->setindex() ".$this->setIndex()."<br/>";
        }
        
        
        

}
    
?> 
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 10-25-2010, 08:11 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Try changing
php Code:
if(($param + $this->adjacents) < $numOfPages)

to

php Code:
if(($param + $this->adjacents) <= $numOfPages)
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
base classes..... allworknoplay Absolute Beginners 16 05-10-2009 08:09 PM
My first pagination class allworknoplay Absolute Beginners 0 04-18-2009 05:01 PM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Advance Pagination Class Rendair Advanced PHP Programming 9 12-13-2007 08:28 AM


All times are GMT. The time now is 05:24 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design