Location: PHPKode > scripts > Page Navigator > page-navigator/class.paging.php
<?php

/*
 ______________________________________________________
/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
|              Class Page Navigator by Efots           |
|                                                      |
|   Feel free to copy, use and change this script as   |
|   long as this part remains unchanged.               |
|                                                      |
|   If you have any questions and or comments please   |
|   E-mail me :                                        |
|				- 'hide@address.com'          				 |
|                                                      |
\______________________________________________________/
 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/

class Paging {
	
	var $int_page_nav;
	var $int_num_group_result;
	var $int_num_result;  
  	var $int_nbr_row;
  	var $int_cur_position;
  	var $int_cur_rows;
  	var $int_cur_group_position;
  	var $str_ext_argv;
  	var $prev_link = false;
  	var $next_link = false;
  
  	function Paging($int_page_nav = 0, $int_nbr_row, $int_cur_group_position, $int_num_group_result, $int_cur_position, $int_num_result, $str_ext_argv = "" ){
    		$this->int_page_nav = $int_page_nav;
			$this->int_nbr_row = $int_nbr_row;
    		$this->int_num_group_result = $int_num_group_result;
    		$this->int_num_result = $int_num_result;
    		$this->int_cur_position = $int_cur_position;
    		$this->int_cur_group_position = $int_cur_group_position;
    		$this->str_ext_argv = urldecode( $str_ext_argv );
  	}

  	function getTotalOfPage(){
		//Set This Thing to Operate In Windows
			$int_nbr_page = bcdiv($this->int_nbr_row, $this->int_num_result, 5);
    		return $int_nbr_page;
		//=====================================
		//Set this thing to operate in linux
			//$int_nbr_page = gmp_div_q($this->int_nbr_row, $this->int_num_result, GMP_ROUND_PLUSINF);
    		//return gmp_strval($int_nbr_page);
		//=====================================		
  	}

	function getTotalOfPageGroup(){
    		$int_nbr_group_page = $this->getTotalOfPage() / $this->int_num_group_result;
    		$int_nbr_group_page = floor( $int_nbr_group_page);
    		$temp = $this->getTotalOfPage() % $this->int_num_group_result;
    		if ($temp > 0) {
    			$int_nbr_group_page = $int_nbr_group_page + 1;
    		}
    		return $int_nbr_group_page;
    		
  	}
	
	function getCurrentPage(){
			$int_cur_page = $this->int_cur_position / $this->int_num_result;
			return number_format( $int_cur_page, 0 );
	}
	
	function getCurrentNumRows() {
			$int_cur_num_rows = ((($this->int_cur_group_position + 1) * $this->int_num_group_result) - 1) * $this->int_num_result;
	 		return $int_cur_num_rows;
	}  
	
  	function getPagingArray(){
	
    		global $PHP_SELF;
    		$str_cur_group_position = 'cgrn'.$this->int_page_nav.'=';
    		$str_cur_position = 'crn'.$this->int_page_nav.'=';

    		$array_paging['lower'] = ( $this->int_cur_position + 1 );

    		if( $this->int_cur_position + $this->int_num_result >= $this->int_nbr_row ){
      			$array_paging['upper'] = $this->int_nbr_row;
    		}else{
      			$array_paging['upper'] = ( $this->int_cur_position + $this->int_num_result );
    		}

    		$array_paging['total'] = $this->int_nbr_row;
    		
			if (((($this->int_cur_group_position * $this->int_num_result) * $this->int_num_group_result) + 1) != $array_paging['lower']) {
    			$previous_page = "<a href=\"$PHP_SELF?".$str_cur_group_position.$this->int_cur_group_position."&".$str_cur_position. ( $this->int_cur_position - $this->int_num_result ).'&'.$this->str_ext_argv ."\" style='text-decoration:none'><b>&laquo;</b></a>";
      			$array_paging['previous_link'] = $previous_page;
    		} else {
				$array_paging['previous_link'] = "<font color=#cccccc>&laquo;</font>";
			}
			
    		if ($this->int_cur_position < $this->getCurrentNumRows()) {
      			$next_page = "<a href=\"$PHP_SELF?".$str_cur_group_position.$this->int_cur_group_position."&".$str_cur_position.($this->int_cur_position + $this->int_num_result).'&'.$this->str_ext_argv ."\" style='text-decoration:none'><b>&raquo;</b></a>";
      			$array_paging['next_link'] = $next_page;
    		} else {
				$array_paging['next_link'] = "<font color=#cccccc>&raquo;</font>";
			}
    		
    		if ( $this->int_cur_group_position > 0) {
    			$previous_group = "<a href=\"$PHP_SELF?".$this->str_ext_argv."&".$str_cur_group_position.($this->int_cur_group_position - 1);
    			$int_new_position = ( ($this->int_cur_group_position - 1) * $this->int_num_group_result ) * $this->int_num_result;
				$array_paging['previous_group'] = $previous_group."&".$str_cur_position.$int_new_position."\" style='text-decoration:none'>&laquo;Prev</a> ";
			} else {
    			$array_paging['previous_group'] = "<font color=#cccccc>&laquo;Prev</font> ";
    		}
		
			if( $this->int_cur_group_position < ($this->getTotalOfPageGroup() - 1) ){
				$int_new_position = (($this->int_cur_group_position + 1) * $this->int_num_group_result) * $this->int_num_result;
				$next_group = "<a href=\"$PHP_SELF?".$this->str_ext_argv."&".$str_cur_group_position.($this->int_cur_group_position + 1);
      			$array_paging['next_group'] = $next_group."&".$str_cur_position.$int_new_position."\">Next&raquo;</a>";
    		} else {
    			$array_paging['next_group'] = "<font color=#cccccc>Next&raquo;</font>";
    		}
		
    		return $array_paging;
  	}

  	function getPagingRowArray(){
    		global $PHP_SELF;
    		$n = 0;
    		$from = $this->int_cur_group_position * $this->int_num_group_result;
			$to = ($this->int_cur_group_position + 1) * $this->int_num_group_result;
 			for( $i = $from; $i < $to; $i++ ){
 				if ($i < $this->getTotalOfPage()) {
    				if( $i == $this->getCurrentPage() ){
    					$array_all_page[$n] = "<font color=#cccccc>". ($i+1) ."</font>";
      				}else{
        				$int_new_position = ($i * $this->int_num_result);
						if (substr($this->str_ext_argv, 0, 1) == "&") {
							$this->str_ext_argv = substr($this->str_ext_argv, 1, strlen($this->str_ext_argv));
						}
        				$array_all_page[$n] = "<a href=\"". $PHP_SELF ."?".$this->str_ext_argv."&cgrn".$this->int_page_nav."=".$this->int_cur_group_position."&crn".$this->int_page_nav."=".$int_new_position."\" class=\"pageNav\">". ($i + 1) ."</a>";
      				}
      				$n += 1;
      			}
    		}
    		return $array_all_page;
  	}
}
?>
Return current item: Page Navigator