![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
03/01/2008, 14:02
|
| | Fecha de Ingreso: diciembre-2007
Mensajes: 30
Antigüedad: 17 años, 2 meses Puntos: 0 | |
Re: Select + Paginación PARTE 2:
Código:
<!-- Fila de la TABLA o FICHA CENTRAL, la información principal -->
<tr>
<td width="568px" height="335px" valign="top">
<table width="567px" height="334px" cellpadding="0" cellspacing="0" border="0px">
<!-- Primera fila es la parte de arriba, sólo el esqueleto con el fondo coloreado -->
<tr>
<td background="img/tabla_arriba.jpg" width="567px" height="21px">
<table width="563px" cellpadding="0" cellspacing="0" border="0px">
<tr>
<td width="40%"><div style="margin-left:50px;" class="titulo">Inmuebles > Categorias</div></td>
<td width="25%"> </td>
<td class="titulo" width="25%">
</td>
</tr>
</table>
</td>
</tr>
<!-- Parte central esqueleto tabla, forzamos la medida para que salga un mínimo de altura, pura estética -->
<tr>
<td width="567px" height="296px" class="td_bordes" valign="top">
<table width="563" height="21" cellpadding="0" cellspacing="0" border="0"style="background-color:#73A532;color:#F9F9F9">
<tr>
<td width="7%"><div class="titulares_inmuebles">Ref</div></td>
<td width="8%"><div class="titulares_inmuebles">Tipo</div></td>
<td width="12%"><div class="titulares_inmuebles">Localidad</div></td>
<td width="13%"><div class="titulares_inmuebles">Calle</div></td>
<td width="10%"><div class="titulares_inmuebles">Modo</div></td>
<td width="12%"><div class="titulares_inmuebles">Precio</div></td>
<td width="20%"><div class="titulares_inmuebles">Propietario</div></td>
<td width="18%"><div class="titulares_inmuebles">Opciones</div></td>
</tr>
</table>
<?
////PAGINACION///
$registros = 5;
if (!$pagina)
{$inicio = 0;$pagina = 1;}
else
{ $inicio = ($pagina - 1) * $registros;}
?>
<!-- -------------------------------- LISTADO DE INMUEBLES empieza ---------------------------------------------- -->
<?php
//si viene del select ordenar, le pasamos el string para que ordene correctamente
if ($ordenar=$_GET['ordenar_select'])
{
$link=conectarse();
$consulta=mysql_query("SELECT*FROM inmuebles",$link);//1º consultamos el numero de registros totales
$total_registros = mysql_num_rows($consulta);
$order = mysql_escape_string( $ordenar );
$consulta=mysql_query("SELECT*FROM inmuebles ORDER BY $order LIMIT $inicio, $registros",$link );
}
else
{
$link=conectarse();
$consulta=mysql_query("SELECT*FROM inmuebles",$link);//1º consultamos el numero de registros totales
$total_registros = mysql_num_rows($consulta);
$consulta=mysql_query("SELECT*FROM inmuebles ORDER BY id LIMIT $inicio, $registros",$link);
}
/// Calculamos el número de páginas que hay
$total_paginas = ceil($total_registros / $registros);
///3º MOSTRAMOS LOS RESULTADOS
while($fila=mysql_fetch_array($consulta))
{
$id = $fila["id"];
$tipo = $fila["tipo"];
$localidad = $fila["localidad"];
$zona = $fila["zona"];
$calle = $fila["calle"];
$numero_y_piso = $fila["numero_y_piso"];
$modo = $fila["modo"];
$precio = $fila["precio"];
$habitaciones = $fila["habitaciones"];
$baños = $fila["baños"];
$luz = $fila["luz"];
$telef_fijo = $fila["telef_fijo"];
$calefaccion = $fila["calefaccion"];
$garaje = $fila["garaje"];
$metros = $fila["metros"];
$observaciones = $fila["observaciones"];
$foto_principal = $fila["foto_principal"];
$foto_2 = $fila["foto_2"];
$foto_3 = $fila["foto_3"];
$foto_4 = $fila["foto_4"];
$propietario = $fila["propietario"];
$telefono = $fila["telefono"];
$aparece_portada = $fila["aparece_portada"];
$menu_movil = $fila["menu_movil"];
if ( $fila_color%2 == 0)
$color = "#FFFFFF";
else
$color = "#f7ffd9";
?>
<div style="width:563px; overflow:hidden;">
<table width="563px" cellpadding="0" cellspacing="0" border="0" bgcolor="<?=$color?>">
<tr>
<td width="10%" height="21px" class="listado_inmuebles" style="padding-left:7px;"><?=$id?></td>
<td width="8%" height="21px" class="listado_inmuebles"><?=$tipo?></td>
<td width="12%" height="21px" class="listado_inmuebles"><?=$localidad?></td>
<td width="13%" height="21px" class="listado_inmuebles"><?=$calle?></td>
<td width="10%" height="21px" class="listado_inmuebles"><?=$modo?></td>
<td width="12%" height="21px" class="listado_inmuebles"><?=$precio?>.000 €</td>
<td width="20%" height="21px" class="listado_inmuebles"><?=$propietario?></td>
<td width="15%" height="21px" class="listado_inmuebles"><a href="./index.php?menu=modificar_inmueble&&id=<?=$id?>" class="enlace4">editar</a> | <a href="#" class="enlace4" onClick="if (confirm('Seguro que desea eliminar el inmueble nº <?=$id?> ?')) window.location='./index.php?menu=categorias&&eliminar=<?=$id?>'">borrar</a></td>
</tr>
</table>
</div>
<?php
$fila_color++;
} // while
?>
<!-- -------------------------------------- LISTADO DE INMUEBLES acaba ---------------------------------------------- -->
</td>
</tr>
<!-- Última fila, parte de abajo de la tabla -->
<tr>
<td width="567px" height="15px"><img src="img/tabla_abajo.jpg" width="567px" height="15px"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<!-- Separación del cuerpo con el borde derecho de la página -->
<td width="12px" height="371px"><img src="img/pixel_transparente.gif"></td>
<!-- Sombra del cuerpo -->
<td background="img/sombra_dcha.jpg" width="10px" height="371px" valign="top"></td>
</tr>
<tr><td colspan="5" style="text-align:center; padding-left:170px;">
<?
/// Enseña la paginación si hay más productos encontrados que la limitación que hicimos
if ($total_registros > $registros)
{
/// En primer lugar construimos el enlace de "anterior", que restará páginas, se pone de dos formas, con enlace si toca y si estamos en la pagina 1 como texto
if(($pagina - 1) > 0)
{ ?>
<a href="index.php?menu=categorias&pagina=<?=$pagina-1?>&<?=$ordenar?>" class="enlace_pagina" ><span style="padding-right:15px;">Anterior</span><img src="./img/flecha_izq.gif" width="13" height="10" border="0"></a>
<? }
else
{ ?>
<span class="sin_pagina"><span style="padding-right:15px;">anterior</span><img src="./img/flecha_izq_gris.gif" width="13" height="10" border="0"></span>
<? }
/// Ahora creamos un bucle para escribir la numeración de las páginas
for ($i=1; $i<=$total_paginas; $i++)
{
if ($i == $pagina)
echo "<span class='enlace_numero'> <b>".$pagina."</b> </span>";
else
{ ?>
<a href="index.php?menu=categorias&pagina=<?=$i?>&<?=$ordenar?>" class="enlace_pagina"> <?=$i?> </a>
<? }
}//for
/// Ahora por último, contruimos el "siguiente" como enlace o como texto, depende ande estemos
if( $pagina < $total_paginas )
{ ?>
<a href="index.php?menu=categorias&pagina=<?=$pagina+1?>&<?=$ordenar?>" class="enlace_pagina"><img src="./img/flecha_dcha.gif" width="13" height="10" border="0"><span style="padding-left:15px;">siguiente</span></a>
<? }
else
{ ?>
<span class="sin_pagina"><img src="./img/flecha_dcha_gris.gif" width="13" height="10" border="0"><span style="padding-left:15px;">siguiente</span></span>
<? }
} /// Cierra el if de mostrar paginación
?>
</td>
<td background="img/sombra_dcha.jpg" width="10"> </td>
</tr>
<!-- Fila de separación del cuerpo con el pie -->
<tr>
<td width="12px" height="7px"><div><img src="img/pixel_transparente.gif"></div></td>
<td width="172px" height="7px"><div><img src="img/pixel_transparente.gif"></div></td>
<td width="7px" height="7px"><div><img src="img/pixel_transparente.gif"></div></td>
<td width="572px" height="7px"><div><img src="img/pixel_transparente.gif"></div></td>
<td width="12px" height="7px"><div><img src="img/pixel_transparente.gif"></div></td>
<td width="10px" height="7px" background="img/sombra_dcha.jpg"></td>
</tr>
|