Les comento: estoy en pleno trabajo final de mi carrera!!Y los wey de mi facultad nunca enseñaron mucho PHP!!Solo frameworks como CAKE o CUMBIA!!!Pero a mi trabajo he decidido hacerlo puramente en PHP!!!Como chiche en él quiero ponerle una paginación!!Pero me he dado conque no me funciona bien!!Le he buscado las mil vueltas pero me salta un error cuando tengo menos registros de los especificados en el LIMIT de mi consulta SQL!!!Me sigue saliendo el "Siguiente" y "Último" como links, aunque no existan más registros!!!Y al darle click me sale "undefined variable impresos"!!!Vengo buscándole la vuelta hace un par de días y no le doy a la tecla justa para solucionarlo!!!!Desde ya a quien pueda tirarme hasta la mínima idea de que puede ser se lo agradecería tanto yo, como los wey de mis compañeros de trabajo final!!!!
A continuación les dejo el código!!!!
<?php
require_once("../conexion/conexion.php");
//***********************************************************************************************************$sql1="select count(*) as cuantos from productores";
$res1=mysql_query($sql1,$conexion);
if ($reg1=mysql_fetch_array($res1))
{
$total=$reg1["cuantos"];
}
$resto=$total % 5;
$ultimo=$total-$resto;
//***********************************************************************************************************if (isset($_GET["pos"]))
{
$inicio=$_GET["pos"];
}else
{
$inicio=0;
}
$sql1="select * from productores order by apellido asc limit $inicio,5";
$res1=mysql_query($sql1,$conexion);
?>
<html>
<head>
<title>Gestión de los Datos de los Productores</title>
<link href="../css/estilos.css" type="text/css" rel="stylesheet">
<script language="javascript" type="text/javascript">
function eliminar (id)
{
if (confirm ("Realmente desea eliminar el registro?"))
{
window.location="delete.php?id_productor=" id;
}
}
</script>
</head>
<body>
<div id="contenedor">
<div id="principal">
<div id="header"></div>
<div id="botonera"></div>
<div id="main"><img src="ima/tit_gs_productores.jpg" hspace="20px"></img>
<div id="tablas">
<table align="center" width="1110">
<tr class="encabezado">
<td valing="top" align="center" width="180">Apellido</td>
<td valing="top" align="center" width="180">Nombre</td>
<td valing="top" align="center" width="200">Domicilio</td>
<td valing="top" align="center" width="200">Localidad</td>
<td valing="top" align="center" width="100">Teléfono</td>
<td valing="top" align="center" width="100">Teléfono 1</td>
<td valing="top" align="center" width="100">E-Mail</td>
<td valing="top" align="center" width="25"></td>
<td valing="top" align="center" width="25"></td>
<?php
if (mysql_num_rows($res1)==0)
{
?>
<tr>
<td valign="top" align="center" width="500" colspan="9" style="background-color:#f0f0f0">
No existen registros sobre productores.</td>
</tr>
<?php
}else
{
$impresos=0;
while ($reg1=mysql_fetch_array($res1))
{
$impresos ;
?>
<tr class="registros">
<td valing="top" align="center" width="180"><?php echo $reg1["apellido"];?></td>
<td valing="top" align="center" width="180"><?php echo $reg1["nombre"];?></td>
<td valing="top" align="center" width="200"><?php echo $reg1["domicilio"];?></td>
<td valing="top" align="center" width="200"><?php echo $reg1["localidad"];?></td>
<td valing="top" align="center" width="100"><?php echo $reg1["telefono"];?></td>
<td valing="top" align="center" width="100"><?php echo $reg1["telefono1"];?></td>
<td valing="top" align="center" width="100"><?php echo $reg1["correo"];?></td>
<td valing="top" align="center" width="25"><a href="modificar.php?id_productor=<?php echo $reg1["id_productor"];?>" title="Modificar"><img src="../ima/edit.jpg" border="0"></td>
<td valing="top" align="center" width="25"><a href="javascript:void(0)" title="Eliminar" onClick="eliminar('<?php echo $reg1["id_productor"];?>')"><img src="../ima/delete.jpg" border="0"></td>
<?php
}
}
?>
<tr>
<td valign="top" align="right" colspan="9">
<a href="agregar.php" title="Agregar Producto"><img src="../ima/add.jpg" border="0"></td>
</tr>
<tr>
<td valing="top" align="center" colspan="9">
</td>
</tr>
<tr>
<td valing="top" align="center" colspan="9">
<?php
if (!$inicio==0)
{
?>
<a href="gs_productores.php?pos=0" title="Primero">Primero
<?php
}else
{
?>
Primero
<?php
}
?>
<!--*************************************-->
<?php
if ($inicio==0)
{
?>
Anterior
<?php
}else
{
?>
<a href="gs_productores.php?pos=<?php echo $inicio-5;?>" title="Anterior">Anterior
<?php
}
?>
<!--*************************************-->
<?php
if ($impresos==5)
{
?>
<a href="gs_productores.php?pos=<?php echo $inicio 5;?>" title="Siguientes">Siguiente
<?php
}else
{
?>
Siguientes
<?php
}
?>
<!--*************************************-->
<?php
if ($inicio==$ultimo)
{
?>
Ultimo
<?php
}else
{
?>
<a href="gs_productores.php?pos=<?php echo $ultimo;?>" title="Ultimo">Ultimo
<?php
}
?>
</td>
</tr>
</table>
</div>
</div>
<div id="footer"></div>
<div id="guarda_izq"></div>
</div>
</div>
</body>
</html>