I have a problem with the variables that came to this query.
Modo, localidad and Tipo, they are no (int) but (string) maybe because of that I have an error that I just realice.
SELECT * FROM DatosInmueble WHERE Tipo=Apartamento :Unknown column 'Apartamento' in 'where clause'
No matter if I convert them before with the (string) info or if I left them like they are, it doesn't work.
<?php
$base="bla";
$tabla="DatosInmueble";
$conexion = mysql_connect('bla') or die(mysql_error());
mysql_select_db($base,$conexion) or die(mysql_error());
$clauses = array();
if (isset($_POST['envio1'] ) && $_POST['envio1'] != -1)
$clauses[] = 'Modo='.$_POST['envio1'];
if (isset($_POST['envio2'] ) && $_POST['envio2'] != -1)
$clauses[] = 'Localidad='.$_POST['envio2'];
if (isset($_POST['envio3'] ) && $_POST['envio3'] != -1)
$clauses[] = 'Tipo='.$_POST['envio3'];
if (isset($_POST['envio4'] ) && $_POST['envio4'] != -1)
$clauses[] = 'Habitaciones='.(int)$_POST['envio4'];
if (isset($_POST['envio5'] ) && $_POST['envio5'] != -1)
$clauses[] = 'Precio<='.(int)$_POST['envio5'];
$query = "SELECT * FROM $tabla";
if (count($clauses) > 0)
$query .= ' WHERE '.join('AND ', $clauses);
$pegar=mysql_query($query, $conexion) or die($query.' :'.mysql_error());
$coincidencias=mysql_num_rows($pegar);
$comienzo=(0+$aumento);//
$query2= "SELECT * FROM $tabla LIMIT $comienzo, 4";
if (count($clauses) > 0)
$query2 .= ' WHERE '.join('AND ', $clauses);
$pegar2=mysql_query($query2, $conexion) or die($query2.' :'.mysql_error());
?>