Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/03/2013, 09:07
marianomartelli
 
Fecha de Ingreso: agosto-2012
Ubicación: Barcelona
Mensajes: 243
Antigüedad: 12 años, 7 meses
Puntos: 1
Problemas en paginacion de registros

Hola,

Tengo el siguiente problema, tengo una pagina que selecciona por categorias y me la envia
a esta pagina (resultados.php) el problema es en la paginacion, ya que la primera vez lo
muestra bien pero al clicar en la siguiente pagina da los siguientes errores;

Notice: Undefined index: idcategoria in C:\wamp\www\sants\resultados.php on line 3
Notice: Undefined variable: categoria in C:\wamp\www\sants\resultados.php on line 150
Notice: Undefined variable: tr_empresas in C:\wamp\www\sants\resultados.php on line 161
Call Stack
Notice: Undefined variable: num_rows in C:\wamp\www\sants\resultados.php on line 169


-------------------------------------------


<?php

if(is_numeric($_POST['idcategoria']) && $_POST['idcategoria']>0){
include("conexion.php");
mysql_select_db("sants");



list($categoria)=mysql_fetch_row(mysql_query("SELE CT categorias FROM categorias WHERE id='".$_POST['idcategoria']."' "));

$consulta=("SELECT * FROM dato_empresa WHERE idcategoria='" .$_POST['idcategoria']."' ORDER BY empresa ");
$datos=mysql_query($consulta,$conexion);
$num_rows=mysql_num_rows($datos);


//AL PRINCIPIO COMPRUEBO SI HICIERON CLICK EN ALGUNA PÁGINA
if(isset($_GET['page']))
{
$page= $_GET['page'];
}
else
{
//SI NO DIGO Q ES LA PRIMERA PÁGINA
$page=1;
}

$verif=$_POST['idcategoria'];

//ACA SE DECIDE CUANTOS RESULTADOS MOSTRAR POR PÁGINA , EN EL EJEMPLO PONGO 15
$rows_per_page= 7;

//CALCULO LA ULTIMA PÁGINA
$lastpage= ceil($num_rows / $rows_per_page);

//COMPRUEBO QUE EL VALOR DE LA PÁGINA SEA CORRECTO Y SI ES LA ULTIMA PÁGINA
$page=(int)$page;

if($page > $lastpage)
{
$page= $lastpage;
}

if($page < 1)
{
$page=1;
}

//CREO LA SENTENCIA LIMIT PARA AÑADIR A LA CONSULTA QUE DEFINITIVA
$limit= 'LIMIT '. ($page -1) * $rows_per_page . ',' .$rows_per_page;

//REALIZO LA CONSULTA QUE VA A MOSTRAR LOS DATOS (ES LA ANTERIO + EL $limit)
$consulta .=" $limit";
$empresas=mysql_query($consulta, $conexion);



$tr_empresas="";


while($row = mysql_fetch_assoc($empresas))


{


$tr_empresas.="



<tr>
<td width=90 rowspan=5><img src=".$row['imagenprin']." hspace=10 alt=Sin_imagen></td>
<td width='372' align='center' ><h4>".$row['empresa']."</h4></td>
<td width=240 rowspan=2><img src=".$row['map_empresa']." hspace=80 ></td>
</tr>
<tr>
<td align='center'>".$row['descripcion']."</td>
</tr>

<tr>
<td align='center'>".$row['direccion']."</td>
<td rowspan=3> <a href='usuario.php?empresa=$row[empresa]'><img src='$row[paginaweb]'style='border:none' hspace=80 height=20></td> </a></td>
</tr>


<tr>
<td align='center'>".$row['telefono']." </td>

</tr>

<tr>
<td align='center'>".$row['horario']."</td>

</tr>

<tr>
<td colspan='6'><hr>
</tr>

";
}
}



?>


<style>
body{font-family:Arial, Helvetica, sans-serif; font-weight:bold;}
table.tabla_empresa{border:none;border-collapse:collapse}
table.tabla_empresa{background-color:#BFBFBF;width:100%;}
table.tabla_empresa th{background-color:#4D4D4D;color:#FFFFFF;border:1px solid #E6E6FA}
table.tabla_empresa td{background-color:#FFFFFF;}
</style>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name : OfficialWork
Description: A two-column, fixed-width design with dark color scheme.
Version : 1.0
Released : 20121012

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>resultados.php</title>
<link href="http://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/paginacion.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery/jquery.gallerax-0.2.js"></script>
<style type="text/css">
@import "gallery.css";
</style>
</head>
<body>

<?php include("menuprincipal.php");?>


<div id="alinear_resultado">
Categoria <?php echo $categoria;?>
</div>

<br />
<div id= "centrar_tabla"
<table class='tabla_empresa'>
<tr>
<th>Imagen</th>
<th>Empresa</th>
<th>Mapa</th>
</tr>
<?php echo $tr_empresas;?>
</table>



<?php
//UNA VEZ Q MUESTRO LOS DATOS TENGO Q MOSTRAR EL BLOQUE DE PAGINACIÓN SIEMPRE Y CUANDO HAYA MÁS DE UNA PÁGINA

if($num_rows != 0)
{
$nextpage= $page +1;
$prevpage= $page -1;

?><ul id="pagination-digg"><?php
//SI ES LA PRIMERA PÁGINA DESHABILITO EL BOTON DE PREVIOUS, MUESTRO EL 1 COMO ACTIVO Y MUESTRO EL RESTO DE PÁGINAS
if ($page == 1)
{
?>
<li class="previous-off">&laquo; Anterior</li>
<li class="active">1</li>
<?php
for($i= $page+1; $i<= $lastpage ; $i++)
{?>
<li><a href="resultados.php?page=<?php echo $i;?>"><?php echo $i;?></a></li>
<?php }

//Y SI LA ULTIMA PÁGINA ES MAYOR QUE LA ACTUAL MUESTRO EL BOTON NEXT O LO DESHABILITO
if($lastpage >$page )
{?>
<li class="next"><a href="resultados.php?page=<?php echo $nextpage;?>" >Siguiente &raquo;</a></li><?php
}
else
{?>
<li class="next-off">Siguiente &raquo;</li>
<?php
}
}
else
{

//EN CAMBIO SI NO ESTAMOS EN LA PÁGINA UNO HABILITO EL BOTON DE PREVIUS Y MUESTRO LAS DEMÁS
?>
<li class="previous"><a href="resultados.php?page=<?php echo $prevpage;?>">&laquo; Anterior</a></li><?php
for($i= 1; $i<= $lastpage ; $i++)
{
//COMPRUEBO SI ES LA PÁGINA ACTIVA O NO
if($page == $i)
{
?> <li class="active"><?php echo $i;?></li><?php
}
else
{
?> <li><a href="resultados.php?page=<?php echo $i;?>" ><?php echo $i;?></a></li><?php
}
}
//Y SI NO ES LA ÚLTIMA PÁGINA ACTIVO EL BOTON NEXT
if($lastpage >$page )
{ ?>
<li class="next"><a href="resultados.php?page=<?php echo $nextpage;?>">Siguiente &raquo;</a></li><?php
}
else
{
?> <li class="next-off">Siguiente &raquo;</li><?php
}
}
?></ul></div><?php
}


?>





</body>
</html>


A ver si alguien me puede revisar el programa.
Gracias y saludos