Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/08/2008, 21:22
datauser
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 19 años, 1 mes
Puntos: 0
Problema al paginar tabla con clase

Hola a todos encontré esta clase para paginar una tabla desde una base de datos mysql la clase funciona casi a la perfección acepto por un detalle, no se porque no avanza a la siguiente pagina, gracias a quienes puedan ayudarme.


Esta es la clase

Código PHP:
<?php

    
class queryList {

        function 
queryList($sql, $link, $page, $rowsPerPage, $pageLimit) {

            
// check the numbers of pages
            
$result        = mysql_query($sql);
            
$totalRows    = mysql_num_rows($result);
            
$totalPages = ceil($totalRows / $rowsPerPage);


            
// verify the given values
            
$page = $page*1; 
            
$rowsPerPage = $rowsPerPage*1; 
            
$pageLimit = $pageLimit*1; 
            if(!
is_int($rowsPerPage) || $rowsPerPage < 1) { $rowsPerPage = 10; }
            if(!
is_int($pageLimit)   || $pageLimit   < 1) { $pageLimit   = 10; }
            if(
$page > $totalPages) { $page = $totalPages; }
            if(!
is_int($page) || $page < 1) { $page = 1; }


            
// build the starting values
            
if($totalPages > $pageLimit ) { $value = $pageLimit; } 
                else { 
$value = $totalPages; }
            if(
$page > $pageLimit) { $i = $page - $pageLimit; $value = $pageLimit+$i; }
            
            
$pages = "";
            
// section for Previous Record
            
if($page > 1){
                
$pages .= '&nbsp;<b>[ <a href='.$link.'&page='.($page-1).'>anterior</a> ] &nbsp;</b>';
            }


            
// build the Pages Browser
            
while (@$i < $value){
                @
$i++;
                if (
$i == $page){
                    
$pages .= '<b>['.$i.']</b>&nbsp;';
                } else { 
                    if(
$i <= $totalPages) { 
                        
$pages .= '<a href='.$link.'&page='.$i.'>'.$i.'</a>'; 
                    }
                }
            }


            
// section for Next Record
            
if($i <= $totalPages){
                if(
$totalPages != $page){
                    
$pages .= '&nbsp;<b>[ <a href='.$link.'&page='.($page+1).'>siguiente</a> ]</b>';
                }
            }


            
// make the return values
            
$this->result = $pages;
            
$this->start  = (($page-1) * $rowsPerPage) + 1;
            
$this->total  = $totalRows;
            
$this->pages  = $totalPages;
            
$this->sql      = $sql.' LIMIT '.($page-1)*$rowsPerPage.','.$rowsPerPage;
            
            
$stop = "";
            if(
$page==$totalPages) { 
        
$this->stop = ($page-1)*$rowsPerPage+($totalRows-(($page-1)*$rowsPerPage)); 
      } else { 
        
$this->stop = $page * $rowsPerPage; 
      }

        } 
// end of query()
        
    
} // end of Class


?>

aqui el uso y resutado

Código PHP:
<?php
include 'db_config.php';
include 
'queryList.php';
$sql = "SELECT * FROM tabla ORDER BY campo DESC";
$queryList = new queryList();
$queryList->queryList($sql, 'lista_contactos.php?', @$page, 10, 20);

//aqui se muestra el resultado
$result = mysql_query ($queryList->sql);

?>

<table cellspacing="0" cellpadding="0" border="0" width="600px">
  <tr>
    <th>Id</th>
    <th>Nombres y apellidos</th>
    <th>Telefono</th>
    <th>Acciones</th>
  </tr>
  <?php
       
while ($fila = mysql_fetch_assoc($result)) {
       
$nombre         = $fila["nombre"];
       
$apellidos     = $fila["apellidos"];
       
$email             = $fila["email"];
       
$telefono       = $fila["telefono"];         
        
?>
   <tr>
    <td><?php echo $nombre ; ?></td>
    <td><?php echo $apellidos ; ?></td>
    <td><?php echo $email; ?></td>
    <td><?php echo $telefono;?></td>
  </tr>
  <?php    } ?>
</table>

<?php
if($queryList->pages > 1) { 
    echo 
'Paginas ('. $queryList->pages .') : ';  
    echo 
$queryList->result; 
}
echo 
"<br>";
if(
$queryList->total >= 1) { 
    echo 
'Archivos mostrados <font color=red>'. $queryList->start .'</font> a <font color=red>'. $queryList->stop .'</font> de <font color=red>'. $queryList->total .'</font>'; 
}

?>
Como podrán ver todo parece estar bien, no se porque no avanza a la siguiente pagina.

Saludos.