Foros del Web » Programando para Internet » PHP »

problema con paginador en la busqueda

Estas en el tema de problema con paginador en la busqueda en el foro de PHP en Foros del Web. ola a todos, mirad mi problema es que q tengo un buscador en mi web con paginacion, con un limite de 10, osea que me ...
  #1 (permalink)  
Antiguo 21/05/2008, 11:47
 
Fecha de Ingreso: febrero-2008
Mensajes: 53
Antigüedad: 16 años, 2 meses
Puntos: 0
problema con paginador en la busqueda

ola a todos,
mirad mi problema es que q tengo un buscador en mi web con paginacion, con un limite de 10, osea que me muestre 10 resultados por pagina, y bien cuando una busqueda que aparecen mas de 10 resultados, y le doy a pag siguiente para q me siga mostrando los resultados, se pierde la busqueda y me pone seccion en construccion q es el mensaje que tengo para cuando algo en la pag no tiene enlace;

he estado leyendo por aki, y es cierto que lo tenia en $_POST, asi que lo que ice fue cambiarlo por $_GET tanto en la pag busqueda.php (en mi caso) como en el formulario de buscar. y ahora cuando ago una busqueda, no me ace nada simplemente va a index.php. no se que puede ser no se si me faltara algun get por cambiar. os dejo los codigos para ver si me podeis ayudar.

busqueda.php
Código PHP:
<?php 
if ($_GET['busqueda']){
    include(
'config.php');
        
$query 'SELECT * from filmoteca1 WHERE titulo LIKE "%'.$_GET['busqueda'].'%" ORDER BY id DESC';

        include(
'paginador.php');
        
$paging =& new Paging($query);
        
$por_pagina=10;
        
$paging->set_perPage($por_pagina);
        
$paging->set_strNext('Siguiente');
        
$paging->set_strPrev('Anterior');
        
$paging->set_varName('pagina');
        
        
$res $paging->getResult();
        
$nav $paging->getMenu();
        
$filas=mysql_num_rows($res);    
    
$n=1;
    echo 
'<h6>Busqueda ('.$filas.')</h6>';
    echo 
'<div id="navegador1" class="paginador">'.$nav.'</div>';
    while(
$registro mysql_fetch_array($res)) {
    if (
$registro['trailer']!='') {$trailer='<img src="img/trailer1.gif" alt="trailer" width="18" height="18" /> ';} else {$trailer='';}
    if (
$registro['blu_ray']!='') {$blu_ray='<img src="img/bluraylogo.gif" alt="blu_ray" width="82" height="32" /> ';} else {$blu_ray='';}
    if (
$registro['novedad']!=0) {$novedad='<img src="img/novedad1.gif" alt="novedad" width="100" height="32" /> ';} else {$novedad='';}
    if (
$registro['descatalogada']!=0) {$descatalogada='<img src="img/descatalogada.gif" alt="descatalogada" width="100" height="32" /> ';} else {$descatalogada='';}
    if (
$registro['serie']!=0) {$serie='<img src="img/serietv.png" alt="serie" width="95" height="35" /> ';} else {$serie='';}
    
$genero=$registro['genero'];
    if (
$genero==1){$gen=' Acción';}
    if (
$genero==2){$gen=' Aventura';}
    if (
$genero==3){$gen=' Artes Marciales';}
    if (
$genero==4){$gen=' Bélico';}
    if (
$genero==5){$gen=' Ciencia Ficción';}
    if (
$genero==6){$gen=' Fantástico';}
    if (
$genero==7){$gen=' Comedia';}
    if (
$genero==8){$gen=' Westerm';}
    if (
$genero==9){$gen=' Documental';}
    if (
$genero==10){$gen=' Drama';}
    if (
$genero==11){$gen=' Histórica / Épica';}
    if (
$genero==12){$gen=' Intriga / Thriller';}
    if (
$genero==13){$gen=' Musical';}
    if (
$genero==14){$gen=' Deportiva';}
    if (
$genero==15){$gen=' Romántica';}
    if (
$genero==16){$gen=' Terror';}
    if (
$genero==17){$gen=' Erótico';}
    if (
$genero==18){$gen=' Animación';}
    if (
$genero==''){$gen=' ';}
    if (
$genero==0){$gen=' ';}    
    echo 
''.$novedad.''.$descatalogada.''.$serie.'
    <div id="elemento'
.$n.'" class="elemento">
        <a href="?seccion=ficha&id='
.$registro['id'].'&titulo='.strtolower($registro['titulo']).'"><img src="img.php?ruta=portadas_peliculas/'.$registro['portada'].'&max=120" alt="'.$registro['titulo'].'" class="portada"/></a>
        <h5>'
.$trailer.$registro['titulo'].'</h5>
        <p><strong>Género:</strong> '
.$gen.'</p>
        <p><strong>Director:</strong> '
.$registro['director'].'</p>
        <p><strong>Actores:</strong> '
.substr$registro['actores'], 0100 ).'&hellip;</p><br />
        <p><img src="img/dvdlogo.gif" alt="dvdlogo" width="82" height="32" /> &nbsp;&nbsp;&nbsp;&nbsp;'
.$blu_ray.'</p>
    </div>'
;
    }
    echo 
'<div id="navegador2" class="paginador">'.$nav.'</div>';
}
else 
{
echo 
'<p>Seccion en construccion</p>';
}
?>
el del formulario
Código PHP:
function buscador() {
echo 
'
             <span><a href="index.php"><h1>VideclubMadison</h1></a> </span>
          <div id="busqueda" class="busqueda">
              <form id="form" name="form" method="get" action="index.php?seccion=busqueda">
                <label for="label">Busqueda: </label>
                <input type="text" name="busqueda" id="busqueda" value="'
.$_GET['busqueda'].'"/>
                <input type="submit" name="buscar" id="buscar" value="Buscar" />
              </form>
          </div>

'
;

espero vuestra respuesa mas sincera y util mil gracias. si os ace falta otro dato mas nada mas pedirlo.
  #2 (permalink)  
Antiguo 21/05/2008, 11:50
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: problema con paginador en la busqueda

Hola chevlo,

Asegúrate que tu clase "paging" que estás usando te transmita las variables, es decir que cuando le piques en "siguiente" en la URL veas las variables de tu búsqueda, si no, el problema reside ahí.

Saludos.
  #3 (permalink)  
Antiguo 21/05/2008, 12:12
 
Fecha de Ingreso: febrero-2008
Mensajes: 53
Antigüedad: 16 años, 2 meses
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>';
    }

}

?>
  #4 (permalink)  
Antiguo 21/05/2008, 12:27
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: problema con paginador en la busqueda

creo que la clase esta bien... no la has modificado o si???
por cierto.... una sugerencia... el paso de varibales (cuando de NEW se trata) por referencia esta obsoleto....

$obj=new StdClass; // OK
$obj=&new stdClass; // OK (pero esta obsoleto en PHP5)
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 21/05/2008, 13:15
 
Fecha de Ingreso: febrero-2008
Mensajes: 53
Antigüedad: 16 años, 2 meses
Puntos: 0
Respuesta: problema con paginador en la busqueda

no, la clase no la modifique, que puedo acer al respecto, no lo entiendo bien lo q quieres decir.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:29.