problema al paginar consulta
Publicado por Cristian (42 intervenciones) el 07/02/2013 17:30:05
Hola quiero paginar, pero no logro realizarlo, no se en que me habre equivocado, espero me ayuden gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require("conexion.php");
require("funciones.php");
$query = "SELECT * FROM empresa ORDER BY nombre ASC";
$queEmp = mysql_query($query, $conexion);
$RegistrosAMostrar=3;
//estos valores los recibo por GET
if(isset($_GET['pag'])){
$RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
$PagAct=$_GET['pag'];
//caso contrario los iniciamos
}else{
$RegistrosAEmpezar=0;
$PagAct=1;
}
$Resultado=mysql_query("SELECT * FROM empresa ORDER BY nombre LIMIT $RegistrosAEmpezar, $RegistrosAMostrar",$conexion);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHP con MySQL: Consultar datos en MySQL</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>Listado de Empresas</h3>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Nombre</th>
<th>Dirección</th>
<th>Teléfono</th>
<th>ID</th>
</tr>
<?php while ($rsEmp = mysql_fetch_assoc($queEmp)) { ?>
<tr>
<td><?php echo $rsEmp['nombre']; ?></td>
<td><?php echo utf8_decode($rsEmp['direccion']); ?></td>
<td><?php echo $rsEmp['telefono']; ?></td>
<td><?php echo '<a href="detallelista.php?id='.$rsEmp['id'].'">Ver</a>'; ?></td>
</tr>
<?php } ?>
</table>
<?php $NroRegistros=mysql_num_rows(mysql_query("SELECT * FROM empresa",$conexion));
$PagAnt=$PagAct-1;
$PagSig=$PagAct+1;
$PagUlt=$NroRegistros/$RegistrosAMostrar;
//verificamos residuo para ver si llevará decimales
$Res=$NroRegistros%$RegistrosAMostrar;
// si hay residuo usamos funcion floor para que me
// devuelva la parte entera, SIN REDONDEAR, y le sumamos
// una unidad para obtener la ultima pagina
if($Res>0) $PagUlt=floor($PagUlt)+1;
//desplazamiento
echo "<a onclick=\"Pagina('1')\">Primero</a> ";
if($PagAct>1) echo "<a onclick=\"Pagina('$PagAnt')\">Anterior</a> ";
echo "<strong>Pagina ".$PagAct."/".$PagUlt."</strong>";
if($PagAct<$PagUlt) echo " <a onclick=\"Pagina('$PagSig')\">Siguiente</a> ";
echo "<a onclick=\"Pagina('$PagUlt')\">Ultimo</a>"; ?>
<p> </p>
</body>
</html>
Valora esta pregunta


0