Tema: Paginacion?
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/04/2005, 14:42
Avatar de PabloP
PabloP
 
Fecha de Ingreso: marzo-2005
Mensajes: 83
Antigüedad: 19 años, 1 mes
Puntos: 0
mira yo saque este codigo de alguna parte de este foro, acomodalo segun tu conveniencia, peri ya lo probe y si me funciono.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body>
<div id="Layer1" style="position:absolute; left:362px; top:50px; width:51px; height:46px; z-index:1">
<?php
$link = mysql_connect("localhost", "rodrigo", "chinito");
mysql_select_db("bdiframe", $link);

if (!isset($pag)) $pag = 1; // Por defecto, pagina 1
//Cuenta cuantas noticias existen en la consulta

$consulta=("SELECT COUNT(*) FROM noticias where noticias.area='".$_GET['selectarea']."' ");

$result1 = mysql_query($consulta, $link);
list($total) = mysql_fetch_row($result1);
$tampag = 5;
$reg1 = ($pag-1) * $tampag;
$consulta2 = ("SELECT id, area FROM noticias WHERE noticias.area='".$_GET['selectarea']."' LIMIT $reg1, $tampag");
$result = mysql_query($consulta2, $link);

if (mysql_num_rows($result)){
echo "<table border = '1'> \n";
echo "<tr><td>id</td><td>area</td></tr> \n";
while ($row = @mysql_fetch_array($result)) {
echo "<tr><td>".$row["id"].
"</td><td>".$row["area"]."</td></tr> \n";
}
echo "</table> \n";
}
else
echo "¡ No se ha encontrado ningún registro !";


/* Funcion paginar
* actual: Pagina actual
* total: Total de registros
* por_pagina: Registros por pagina
* enlace: Texto del enlace
* Devuelve un texto que representa la paginacion
*/
function paginar($actual, $total, $por_pagina, $enlace) {
$total_paginas = ceil($total/$por_pagina);
$anterior = $actual - 1;
$posterior = $actual + 1;

if ($actual>1)
$texto = "<a href=\"$enlace$anterior\">&laquo;</a> ";
else
$texto = "<b>&laquo;</b> ";
for ($i=1; $i<$actual; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
$texto .= "<b>$actual</b> ";
for ($i=$actual+1; $i<=$total_paginas; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
if ($actual<$total_paginas)
$texto .= "<a href=\"$enlace$posterior\">&raquo;</a>";
else
$texto .= "<b>&raquo;</b>";
return $texto;
}

echo paginar($pag, $total, $tampag, "prueba.php?selectarea=".$_GET['selectarea']."&pag=");
?>
</div>
</body>
</html>