Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/08/2008, 23:48
datauser
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 16 años, 7 meses
Puntos: 0
Ayuda para paginar registros

Hola foreros, por favor que alguien me ayude tengo el siguiente problema con una clase para paginar registros desde una base de datos mysql, el avance de la paginación funciona perfectamente con los link “anterior” y “siguiente” pero NO con los link números de las paginas.

El problema esta es aquí: [anterior] [1] 2 3 4… [Siguiente], en los números que pongo con negrita.

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:
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?'$_GET['page'], 1020);

//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>'
}

?>
No se explique bien, Gracias a quien pueda ayudarme.