0
In this search when the array returns the 4
as the SQL demonstrated below, I need the system to return all the results whose number of dorms and >= 4
. You can help me get this result.
I converted the column to INT
. It’s ugly in the DB
, I didn’t make it, I was ready.
# Selecionando conforme quantidade de dormitorios
$dormi = $_POST['dorm'];
if (isset($_POST['dorm']) && is_array($_POST['dorm']) && count($_POST['dorm']) > 0){
$where .= " DORMITORIO IN (". implode(', ', $dormi).") AND ";
if (in_array(4, $_POST['dorm'])){
$where .= trim($where,' AND ').' OR DORMITORIO >= 4 AND ';
}
}
This is the SQL record of this search:
SELECT * FROM immovable WHERE 1=1 AND DORMITORIO IN (1, 2, 3, 4)
@Bacco, I think he sends this data with
checkbox
, where you can have several options selected.– KaduAmaral
Maybe, but it’s a little strange that someone wants a house with one or four bedrooms only... and I’ve seen a lot of real estate. But you’ll know, right? :)
– Bacco
Yeah, rs... here’s another question from him, I think it’s from the same system. http://answall.com/questions/31319/como-enviar-dados-de-checkbox-para-uma-consulta-com-mysql
– KaduAmaral
@Bacco can be strange who is looking for 1 room search for 4 at the same time but it is not so strange to look for 3 and 4. And if I put
>=4
eliminate 75% of the search properties as these are 3 rooms at least in this system.– Marcos Vinicius
@Marcosvinicius of course, you must do whatever is convenient. It is that in these cases usually the staff adopts the minimum (from 1 upwards, from 2 upwards, from 3 upwards) because who seeks 2, probably will accept a house with 3 bedrooms, but not the reverse. In your specific case, of course you should do the best way that pleases your customer.
– Bacco
It is extremely logical what you said !!!
– Marcos Vinicius
Then the query becomes simpler still, you don’t need the array.
WHERE DORMITORIO > '.(0+@$_POST['dorm']);
(I wore the best of style XGH to come up with this comment code :D )– Bacco