Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/07/2010, 11:33
condesitadeirun
 
Fecha de Ingreso: noviembre-2007
Ubicación: Irun
Mensajes: 79
Antigüedad: 16 años, 6 meses
Puntos: 0
Pregunta Paginacion con Php&MySql

Muy buenas,

Me encuentro desarrollando un sistema de navegacion para unos resultados de una base de datos.

Cuando desarrollo la consulta y no pongo como variable la tabla ( pongo una variable estatica), me salen correctamente los resultados, sin embargo cuando pongo como variable la tabla en la primera pagina me sale correcta, sin embargo al navegar por las diferentes paginas ya no me hace bien la consulta... y no se exactamente porque ocurre eso. Os copio el código.
Muchas gracias
Juncal


Cita:

include("conexion.php");
$pueblo=$_POST['localidad'];
$limit = 5;
// pagina pedida
$pag = (int) $_GET["pag"];
if ($pag < 1)
{
$pag = 1;
}
$offset = ($pag-1) * $limit;


$sql = "SELECT SQL_CALC_FOUND_ROWS ref,tipo FROM $pueblo LIMIT $offset, $limit";
$sqlTotal = "SELECT FOUND_ROWS() as total";

$rs = mysql_query($sql);
$rsTotal = mysql_query($sqlTotal);

$rowTotal = mysql_fetch_assoc($rsTotal);
// Total de registros sin limit
$total = $rowTotal["total"];

?>


<table border="1" bordercolor="#000">
<thead>
<tr>
<td>Id</td>

</tr>
</thead>
<tbody>

<?php
while ($row = mysql_fetch_assoc($rs))
{
$ref = $row["ref"];
$tipo=$row["tipo"];

?>

<tr>
<td>
<?php echo $ref; ?>
</td>
<td>
<?php echo $tipo; ?>
</td>
</tr>

<?php
}
?>

</tbody>
<tfoot>
<tr>
<td colspan="2">

<?php
$totalPag = ceil($total/$limit);
$links = array();
for( $i=1; $i<=$totalPag ; $i++)
{
$links[] = "<a href=\"?pag=$i\">$i</a>";
}
echo implode(" - ", $links);
?>