Working on a real estate site where a user can search for property based on minimum and maximum price.
Now in the database I have fields like property_price_maximum and property_price_minimum, both set to INT.
These are the two combo boxes for user to enter values.
Min Max
5 lacs 25 lacs
25 lacs 50 lacs
50 lacs 70 lacs
70 lacs 1.5 Cr
1.5 Cr 5 Cr
Note: lacs = lakh and Cr = Crore. (100 lacs = 1Crore) [Added for info]
For ints i tried this:
select property_price_min,property_price_max from properties where (property_price_min between 25 and 55) and (property_price_max between 25 and 55);
Works corrrectly,but when there is a Crore value like 1.5 this fails as I have not entered the Units in the database.
When I changed the fields in database to Varchar and tried similar query with units the results were not correct(Obviously because BETWEEN compares numerals only as per my knowledge)
SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id where (cities.city_name like '%".$citySearch."%' and locality.locality_name like '%".$localitySearch."%') and (property_price_min between '78 Lacs' and '80 Lacs');
I want to get properties where min and max price is between the users range.The problem is the UNITS over here bcoz if the user selects 25 lacs and 1.5 Cr then my query wont return correct.
I don’t think LIKE is a good option as far as numbers are concerned .
Any kind of helpful comments would be appreciated.
You should store all your values as “lacs”. Since 100 lacs = 1 crore, you should store 1.5 crore as 150 lacs, and do all your calculations in lacs.