1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Paginator class: browsing pages doesn't work

Discussion in 'PHP' started by motofzr1000, Jul 8, 2009.

  1. #1
    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:

    
    <?php
    class paginator {
    
    	var $current_page;
    	var $total;
    	var $per;
    	
    	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";
    		
    	}
    
    }
    PHP:
    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)


    
      $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();
    
    PHP:
    Could someone tell me what could be wrong with this?

    cheers,

    motofzr1000
    SEMrush
     
    motofzr1000, Jul 8, 2009 IP
    SEMrush