Ver Mensaje Individual
  #3 (permalink)  
Antiguo 21/05/2008, 12:12
chevlo
 
Fecha de Ingreso: febrero-2008
Mensajes: 53
Antigüedad: 17 años
Puntos: 0
Respuesta: problema con paginador en la busqueda

ok lo voy a mirar de todas formas te lo pongo por si quieres echar un vistazo

Código PHP:
<?php
// Clase de paginacion
class Paging
{
  
// Varibles to be uses as Menu Config
  // If not set with the proper Function
  // they get a default Value
    
    /* How Many result Per Page
    @INT
    */
    
var $perPage;
    
/* String with the next Link-Text
    @STR : Can be html to use images <img src="img/next.gif" alt="next">
    */
    
var $strNext;
    
/* String with the next Link-Text
    @STR : Can be html to use images <img src="img/next.gif" alt="next">
    */
    
var $strPrev;
    
/* String with the Var name that will be used for Paging
    @STR : Use Only [a-z][A-Z] Chars Please (DO NOT INCLUDE [0-9])
    */
    
var $varName;
    
    
// Variables For Calculation Of Result
    
    /* Variable that Holds The Number Of Results In the Query
    @INT
    */
    
var $total;
    
/* Total Number Of Pages
    $INT
    */
    
var $totalPages;
    
/* Variable that Holds the number of the begibib in the query
    @INT
    */
    
var $start;
    
/* THe current Value of $_GET[ $varName ]
    @INT
    */
    
var $page;
    
    
    
// Variables for Storing Mysql Querys And Results
    
    /* This Variable Holds the Original Query Of the User
    @STR
    */
    
var $sql;
    

    
// Class Constructor PASS the query
    // Only Selects
    
function Paging($sql)
    {    
        
// Store the Original SQL
        
$this->sql $sql;  
        
// Get The SQL Count Query String
        
$sqlCount eregi_replace("select (.*) from""SELECT COUNT(*) FROM"$this->sql);
        
// Fetch the Result
        
$sqlCount mysql_query($sqlCount);
        
// Set the Total
        
$this->total mysql_result($sqlCount,0,0);
    }
    
    
// Method Used Internaly to Propage the URL GET Variables
    
function propagate(&$a,$pref='',$f='',$idx='')
    {
      
$ret '';
      foreach (
$a as $i => $j)
      {
        if (
$i != $this->varName)
        {
                if (
$idx != '')
            {
              
$i $idx."[$i]";
            }
            if (
is_array($j))
            {
              
$ret .= $this->propagate($j,'',$f,$i);
            }
            else
            {
              
$j=urlencode($j);
              if (
is_int($i))
              {
                
$ret .= "$f$pref$i=$j";
              }
              else
              {
                
$ret .= "$f$i=$j";
              }
               }
           }
    
$f='&';
      }
        return 
$ret;
    }


    
// Methods For Configuration
    
function set_perPage($value)
    {
            
$this->perPage $value;
    }    
    
    function 
set_strNext($value)
    {
        
$this->strNext $value;
    }
    
    function 
set_strPrev($value)
    {
        
$this->strPrev $value;
    }
    
    function 
set_varName($value)
    {
        
$this->varName $value;
    }

    function 
sysConfig()
    {
        
// This Method Calls All all the Config Methods
        // To configure the Class
        
if (empty($this->varName))
        {
            
$this->set_varName('page');
        }
        if (empty(
$this->strPrev))
        {
            
$this->set_strPrev('<< ');
        }
        if (empty(
$this->strNext))
        {
            
$this->set_strNext(' >>');
        }
        if (empty(
$this->perPage))
        {
            
$this->set_perPage(10);
        }
        
$this->page = isset($_GET[$this->varName]) ? $_GET[$this->varName] : 1;
        
$this->totalPages ceil($this->total $this->perPage);
        
$this->start = ($this->page 1) * $this->perPage;
    }

    function 
getMenu()
    {    
        
// Config CALL
            
$this->sysConfig();
            
$string $this->propagate($_GET);
            
$more $this->page 1;
            
$less $this->page 1;
            if (
$this->page != 1)
            {
                 
$navResult[] = "<a href=\"$_SERVER[PHP_SELF]?$string&$this->varName=$less\">$this->strPrev</a>";
            }
            
/*for ($i=1;$i<=$this->totalPages;$i++)
            {
                $navResult[] = ($this->page == $i) ? " <strong>$i</strong> /  " : "<a href=\"$_SERVER[PHP_SELF]?$string$this->varName=$i\">$i</a> / ";                 
            }*/
            
if ($this->page != $this->totalPages)
            {
                
$navResult[] = "<a href=\"$_SERVER[PHP_SELF]?$string&$this->varName=$more\">$this->strNext</a>";
            }
            
$navResult = @implode($navResult,' | ');
            
//$navResult = "Página $this->page /  $this->totalPages - $this->total Automoviles<br/>" .$navResult;
            
return $navResult;    
    }
    
    function 
getResult()
    {
        
$this->sysConfig();
        
$this->sql .= " LIMIT $this->start, $this->perPage";
        
$result mysql_query($this->sql);
        return 
$result;
    }
    
    function 
debug()
    {
        echo 
'<textarea cols="60" rows="10">';
        
print_r($this);
        echo 
'</textarea>';
    }

}

?>