Problem with paginator class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
northernlight_10
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 4:41 am

Problem with paginator class

Post by northernlight_10 »

Hi,

I'm having a problem with a paginator class. My page shows the correct amount of pages, but when I click on the link to go to the next page, the following page only shows the content of the first page, so I can't actually browse the pages.

This is the class that I'm using:

Code: Select all

 
<?php
class paginator {
 
    var $current_page;
    var $total;
    var $per;
    
    /*
    Page should be made by uribuilder
    So should the stuff in toolbuilder
    This way I could choose to have either a raw or friendly setup ? vs /
    */
    
    function paginator () {
    }
        
    function render() {
    
        $this->current_page = $_GET['page']; if (empty($this->current_page)) { $this->current_page = 1; }
        $number_of_pages                = ceil($this->total / $this->per);
        
        if ($number_of_pages > 1) {
            $previous_page              = $this->current_page - 1; if ($previous_page < 1) { unset($previous_page); }
            $next_page                  = $this->current_page + 1; if ($next_page > $number_of_pages) { unset($next_page); }
        }
 
        echo '<div class="paginator">'."\n";
        echo '<ul>'."\n";
        
            for($i=1; $i < $number_of_pages+1; $i++) {
            
        echo '<li><a title="Page '.$i.' of '.$number_of_pages.'"';
            if ($this->current_page == $i) { 
        echo ' class="active"';
            } 
        echo' href="';
        echo uri_builder('page='.$i);
        echo '">';
        echo $i;
        echo '</a></li>'."\n";
            
            }   
        
        if ($previous_page) {
        echo '<li><a title="Previous Page" href="'.uri_builder('page='.$previous_page).'">&lsaquo;&lsaquo;</a></li>';
        }
        if ($next_page) {
        echo '<li><a title="Next Page" href="'.uri_builder('page='.$next_page).'">&rsaquo;&rsaquo;</a></li>';
        }
        echo '</ul>'."\n";
        echo '</div>'."\n";
        
    }
 
}
The following code is from the page with the ouput:
(results_per_page comes from a separate config file which is included in the output page)

Code: Select all

 
  $paginator->total   = count($mysql->mysql_array("SELECT * FROM productfiles"));
  $paginator->per    = $module['config']['display']['results_per_page'];
  
  $order      = order(array("orderby" => $_GET['orderby'],"order" => $_GET['order']));
  $limit      = limit(array("current_page" => $paginator->current_page,"per" => $paginator->per));
  $query      .= " SELECT * FROM productfiles";
  $query      .= " ".$order['query'];
  $query      .= " ".$limit['query'];
  $paginator->render();
 



Could someone tell me what could be wrong with this?

cheers,

northernlight_10
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Problem with paginator class

Post by JAB Creations »

Time to learn MySQL's LIMIT clause!

Show chat room messages 30-60...

Code: Select all

 SELECT *FROM chatLIMIT 30 , 30 
Post Reply