<!--COMIENZO PAGINADOR-->
<?php
$filtro='';
$tipo=$_POST['interes'];
$provincia=$_POST['sprovincia'];
$year=$_POST['ano'];
$categoria=$_POST['scategoria'];
$marca=$_POST['smarca'];
$min=$_POST['pminimo'];
$max=$_POST['pmaximo'];
$busqueda=$_POST['bpalabra'];
if(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se vende") AND ($busqueda!="bpalabra")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\" AND texto=\"$busqueda\"";
}elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se compra") AND ($busqueda!="bpalabra")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\" AND texto=\"$busqueda\"";
}elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="-seleccione marca") AND ($min!="selec") AND ($max!="selec") AND ($tipo!='se vende') AND ($tipo!='se compra') AND ($busqueda!="bpalabra")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2='se vende' AND tipo2='se compra' AND texto=\"$busqueda\"";
}elseif(($provincia!="-selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="-seleccione marca") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se compra")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\"";
}elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\"";
}elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($min!="selec") AND ($max!="selec")){
$filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND precio>=\"$min\" AND precio<=\"$max\"";
}elseif(($provincia!="selec") AND ($categoria!="selec") AND ($min!="selec") AND ($max!="selec")){
$filtro="provincia=\"$provincia\" AND tipo1=\"$categoria\" AND precio>=\"$min\" AND precio<=\"$max\"";
}elseif(($provincia!="selec") AND ($min!="selec") AND ($max!="selec")){
$filtro="provincia=\"$provincia\" AND precio>=\"$min\" AND precio<=\"$max\"";
}elseif(($min!="selec") AND ($max!="selec")){
$filtro="precio>=\"$min\" AND precio<=\"$max\"";
}elseif(($min!="selec") AND ($max=="selec")){
$filtro="precio>=\"$min\"";
}elseif(($min=="selec") AND ($max!="selec")){
$filtro="precio<=\"$max\"";
}elseif(($provincia!="selec")){
$filtro="provincia=\"$provincia\"";
}elseif(($categoria!="selec")){
$filtro="tipo1=\"$categoria\"";
}elseif(($year!="")){
$filtro="year=\"$year\"";
}elseif(($busqueda!="")){
$filtro="texto like '%$busqueda%'";
}elseif(($marca!="selec")){
$filtro="marca=\"$marca\"";
}elseif(($tipo!="todo")){
$filtro="tipo2=\"$tipo\"";
}elseif(($tipo=="todo")){
$filtro="tipo2='se vende' or tipo2='se compra'";
}elseif(($min=="selec") AND ($max=="selec")){
$filtro="id_anunciante=90000";
}elseif(($busqueda=="")){
$filtro=$_GET['bpalabra'];
}
$RegistrosAMostrar=4;
//estos valores los recibo por GET
$RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
$PagAct=$_GET['pag'];
//caso contrario los iniciamos
}else{
$RegistrosAEmpezar=0;
$PagAct=1;
}
$Resultado = mysql_query("SELECT * FROM anuncios WHERE $filtro ORDER BY id_anuncio LIMIT $RegistrosAEmpezar, $RegistrosAMostrar", $link); // CODIGO PARA BUSCAR SI HAY UN ERROR EN LA CONSULTA
$error = mysql_error($link); // $link es la variable de conexión
if ($error!=null)
{
print("Ocurrio; el Siguiente Error:\n ".$error);
}
// FIN DE LA BUSQUEDA DE ERROR
echo "<table border='1px'>";
echo "<tr>";
echo "<td>".$MostrarFila['titulo']."</td>";
echo "<td><img src='".$MostrarFila['foto1']."' WIDTH=105 HEIGHT=97></img></td>";
echo "<td>".$MostrarFila['precio']."</td>";
echo "</tr>";
}
echo "</table>";
//******--------determinar las páginas---------******//
$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 $filtro;
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>";
?>
<!--FIN PAGINADOR-->