Amigos como va, estoy haciendo un gran proyecto y se me complica en un tema, estoy haciendo un php mysql ajax pagination, pero el problema es que se me borran los filtros cuando quiero realizar el paso de pagina en pagina, no se que es lo que pasa, el primer resultado me tira bien el filtro de mi consulta, ahora cuando quiero pasar a la siguiente pagina me hace un reload y se pierde la consulta y me lista todos los datos de la base de datos, ya no se que hacer una ayudita por favoooor!!!! saludos y buen año
este es mi codigo
Código PHP:
<? include ("login/dbconexion.php");
$tipo = $_POST ['tipo'];
$amb = $_POST ['amb'];
$localidad = $_POST ['localidad'];
$barrio = $_POST ['barrio'];
$tprop = $_POST ['tprop'];
$precio = $_POST ['precio'];
$RegistrosAMostrar=2;
if(isset($_GET['pag'])){
$RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
$PagAct=$_GET['pag'];
//caso contrario los iniciamos
}else{
$RegistrosAEmpezar=0;
$PagAct=1;
}
$query = "SELECT * FROM propiedades";
$conditions = array();
if( $tipo != "0" ) {
$conditions[] = "tipo = '$tipo'";
}
if( $amb != "0" ) {
$conditions[] = "amb = '$amb'";
}
if( $localidad != "0" ) {
$conditions[] = "localidad = '$localidad'";
}
if( $barrio != "0" ) {
$conditions[] = "barrio = '$barrio'";
}
if( $tprop != "0" ) {
$conditions[''] = "tprop = '$tprop'";
}
if( count( $conditions[''] ) > 0 ) {
$query .= " WHERE " . implode ( " AND ", $conditions) ; // = SELECT * FROM propiedades WHERE pais = 'españa' AND localidad = 'galicia' AND etc
}
//$result=mysql_query("select * from propiedades ORDER BY codigo LIMIT $RegistrosAEmpezar, $RegistrosAMostrar",$con);
$sql = mysql_query($query ."ORDER BY codigo LIMIT $RegistrosAEmpezar, $RegistrosAMostrar",$con);
echo $query."<br><br><br>";
echo "Su búsqueda fue:<br>";
echo "<br>".$tprop." en ".$tipo." ".$amb." ambientes ".$barrio." ".$localidad;
echo "<br>";
echo "<br>Precio".$precio."<br>";
//while($row=mysql_fetch_array($result))
while($row=mysql_fetch_array($sql)){
echo "<tr>";
echo "<td height='10' align='right' valign='top'><strong></strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='417' height='272' align='left' valign='top'>";
echo "<table width='415' border='0'>";
echo "<tr>";
echo "<td width='409' height='23'>";
echo "<table width='462' border='0' align='left'>";
echo "<tr valign='top'>";
echo "<td height='29' align='right'> </td>";
echo "<td align='right'><strong>Codigo de propiedad </strong>" .$row['codigo']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='276'>".$row['titulo']."<br></strong></td>";
echo "<td width='176'>".$row['estado']."</td>";
echo "</tr>";
echo "</table></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='225' align='left' valign='top'><table width='418' border='0'>";
echo "<tr>";
echo "<td width='212' height='165' align='left' valign='top'><table width='156' border='0'>";
echo "<tr>";
echo "<td width='150' height='56'>";
echo "<table width='203' border='0'>";
echo "<tr>";
echo "<td width='197'>";
echo "<p><img src='".$row['foto1']."' width='160' height='120'/></p>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td height='24'> </td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "</td>";
echo "</tr>";
echo "</table></td>";
echo "<td width='196' align='left' valign='top'>";
echo "<p><br>";
echo "<strong>Direccion:</strong><br>".$row['direct']."<br>".$row['barrio']." ".$row['localidad']."<br>";
echo "<strong>Tipo:</strong> ".$row['tprop']."<br>";
echo "<strong>Ambientes:</strong> ".$row['amb']."<br>";
echo "<strong>Metros totales:</strong> ".$row['m2t']."<br>";
echo "<strong>Antiguedad:</strong> ".$row['ant']." anos<br>";
echo "</p>";
echo "<table width='223' border='0' align='right'>";
echo "<tr>";
echo "<td width='48'> </td>";
echo "<td width='165'><strong>Precio ".$row['to'].":</strong> ".$row['precio']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td height='74'> </td>";
echo "<td><a href='detalle.php?codigo=".$row['codigo']."'>Ver mas</a></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table></td>";
echo "</tr>";
echo "</table>";
echo "<p>";
echo "</p>";
echo "<p> </p>";
echo "<p><br>";
echo "</p></td>";
echo "</tr>";
}
echo "</table>";
//cerramos el conjunto de resultado y la conexión con la base de datos
// $sql = mysql_query($query ."ORDER BY codigo LIMIT $RegistrosAEmpezar, $RegistrosAMostrar",$con);
$NroRegistros= mysql_num_rows (mysql_query($query .'ORDER BY codigo',$con));
$PagAnt=$PagAct-1;
$PagSig=$PagAct+1;
$PagUlt=$NroRegistros/$RegistrosAMostrar;
$Res=$NroRegistros%$RegistrosAMostrar;
if($Res>0) $PagUlt=floor($PagUlt)+1;
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>";
?>
La parte ajax, creo que el problema es aquí por que no se como pasar la búsqueda por ajax
documento ajax
Código PHP:
function objetoAjax(){
var xmlhttp=false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function Pagina(nropagina){
//donde se mostrará los registros
divContenido = document.getElementById('contenido');
ajax=objetoAjax();
//uso del medoto GET
//indicamos el archivo que realizará el proceso de paginar
//junto con un valor que representa el nro de pagina
ajax.open("GET", "paginador.php?pag="+nropagina);
divContenido.innerHTML= '<img src="anim.gif">';
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divContenido.innerHTML = ajax.responseText
}
}
//como hacemos uso del metodo GET
//colocamos null ya que enviamos
//el valor por la url ?pag=nropagina
ajax.send(null)
}