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 .= ' <b>[ <a href='.$link.'&page='.($page-1).'>anterior</a> ] </b>';
}
// build the Pages Browser
while (@$i < $value){
@$i++;
if ($i == $page){
$pages .= '<b>['.$i.']</b> ';
} else {
if($i <= $totalPages) {
$pages .= '<a href='.$link.'&page='.$i.'>'.$i.'</a>';
}
}
}
// section for Next Record
if($i <= $totalPages){
if($totalPages != $page){
$pages .= ' <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
?>
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'], 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>';
}
?>