Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/07/2008, 11:34
wisygo
 
Fecha de Ingreso: julio-2008
Mensajes: 2
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Ayuda con buscador php y mysql. Os lo agradezco

El codigo de funciones.php que no me entraba es:

Código PHP:
<?php
// Agradecimientos a Arias por el GRAN paginador que pueden bajar
// De esta web: http://www.php-hispano.net
class Paginador {

  var 
$campos;
  var 
$tabla;
  var 
$where;
  var 
$enlace;
  var 
$epp;
  var 
$mysql;
  var 
$actual;
  var 
$elementos;

  function 
paginador ($campos$tabla$where$enlace$epp$mysql) {
    
$this->campos $campos// Campos a seleccionar de la tabla
    
$this->tabla $tabla// Tabla o tablas con las que vamos a trabajar
    
$this->where $where// Where de la consulta
    
$this->enlace $enlace// URL utilizada para generar los enlaces, se a?ra simplemente el numero al final de este
    
$this->epp max(1, (int)$epp); // Numero de Elementos Por Pagina
    
$this->mysql $mysql// Resource de conexion a MySQL
    
$this->actual min($this->max_paginas(), max(1, isset($_GET['pag']) ? $_GET['pag'] : 1)); // Pagina actual
  
}

  function 
get_elementos($type MYSQL_NUM) {
    
$inicio = ($this->actual 1) * $this->epp;
    
$result mysql_query('SELECT '.$this->campos.' FROM `'.$this->tabla.'` WHERE '.$this->where.' LIMIT '.$inicio.', '.$this->epp$this->mysql) or die (mysql_error());
    
$array = array();
    while (
$row mysql_fetch_array($result$type)) $array[] = $row;
    return 
$array;
  }

  function 
get_paginas($rango 0) {
    
$rango max (0min(10, (int)$rango));
    if (
$rango) { $inicio = ($this->actual $rango 1) ? $this->actual $rango$fin = ($this->actual $rango > ($max $this->max_paginas())) ? $max $this->actual $rango; }
    else { 
$inicio 1$fin = ($max $this->max_paginas()); }
    
$return = ($this->actual != 1)? '<a href="'.$this->enlace.($this->actual-1).'">Anterior</a> ' 'Anterior ';
    if (
$inicio 1$return .= '... ';
    for (
$i=$inicio$i<=$fin$i++) {
      
$return .= ($i != $this->actual)? '<a href="'.$this->enlace.$i.'">'.$i.'</a> '$i.' ';
    }
    if (
$fin $max$return .= ' ...';
    return 
$return . ($this->actual != $this->max_paginas() && !$this->vacio() ? ' <a href="'.$this->enlace.($this->actual+1).'">Siguiente</a>' ' Siguiente');
  }

  function 
num_elementos() {
    if (empty(
$this->elementos)) {
     
$this->elementos mysql_query('SELECT COUNT(*) FROM `'.$this->tabla.'` WHERE '.$this->where$this->mysql) or die (mysql_error());
     
$this->elementos mysql_num_rows($this->elementos) ? mysql_result($this->elementos0) : 0;
    }
    return 
$this->elementos;
  }

  function 
max_paginas() {
    return (
$max ceil($this->num_elementos() / $this->epp))? $max 1;
  }

  function 
vacio() {
    return 
$this->num_elementos() == 0;
  }
}

// Funcion de Seguridad usada para proteger la Base de Datos de posibles ataques
function Seguridad($variable)
{
$variable addslashes(trim($variable));

$var htmlentities($variable);

return 
$var;
}
?>
Gracias.