I am creating an advanced search feature for a website and it's almost done, I'm only having one major issue. I am matching the rooms like this:
AND Rooms=" .$_SESSION["room"] ."
and tried this as well:
AND (Rooms=" .$_SESSION["room"] ." OR Rooms IS NULL)
But the problem is if the user doesn't insert any value in the room input it won't show any room. And with the IS NULL code if I insert "8" in the rooms input if there is no matches it will display all values from the DB. I don't want to make the input as required.
I just need a solution with mysql for when the field is empty return all values without using this:
if ($_SESSION["room"]==NULL) {}
else{}
Full query:
`SELECT * FROM secret WHERE secretIDName='1' AND NatureTypeIDName LIKE '%" .$_SESSION["nature"] ."%' AND (NettArea>="
.$_SESSION["NettArea"] ." OR NettArea IS NULL) AND ConditionTypeIDName LIKE'%" .$_SESSION["lifestyle"]
."%' AND ((SUBSTRING_INDEX(SUBSTRING_INDEX(BusinessTypeValues,'|',4),'|',-1)>="
.$_SESSION["BusinessTypeValuesMin"]
." AND SUBSTRING_INDEX(SUBSTRING_INDEX(BusinessTypeValues,'|',4),'|',-1)<="
.$_SESSION["BusinessTypeValuesMax"]
.") OR SUBSTRING_INDEX(SUBSTRING_INDEX(BusinessTypeValues,'|',4),'|',-1) = '') AND (SUBSTRING_INDEX(SUBSTRING_INDEX(BusinessTypeValues,'|',2),'|',-1)='"
.$_SESSION["BusinessTypeValuesType"]
."' OR SUBSTRING_INDEX(SUBSTRING_INDEX(BusinessTypeValues,'|',2),'|',-1)='') AND GarageArea>="
.$_SESSION["GarageArea"]
." AND (LocationIDName LIKE '%"
.$_SESSION["zone1"]
."%' AND LocationIDName LIKE '%"
.$_SESSION["zone2"]
."%' AND LocationIDName LIKE '%"
.$_SESSION["zone3"]
."%') AND (Rooms="
.$_SESSION["room"]
.") LIMIT "
.($page-1)*$Page
.", " .$Page ."";`
if(!empty('$_SESSION["room"]')){AND Rooms=" .$_SESSION["room"] ;"}ifs, You can do it like(Rooms=".$_SESSION["room"]." OR ".$_SESSION["room"]." = '')