I need to create a results query for a simple (property website) search form and I’m struggling with the price field somehow! The search form has just four criteria (property_type, property_location, price_from and price_to) and it’s the last two of which I’m not sure how to handle them inside the query. This is the properties table:
CREATE TABLE IF NOT EXISTS `properties` (
`property_id` int(8) unsigned NOT NULL auto_increment,
`type_id` smallint(2) NOT NULL default '0',
`property_type_id` smallint(2) NOT NULL default '0',
`county_id` smallint(2) NOT NULL default '0',
`city_id` smallint(2) NOT NULL default '0',
`district_eng` varchar(128) default NULL,
`district_gr` varchar(128) default NULL,
`plot_size` varchar(128) default NULL,
`living_space` varchar(128) default NULL,
`rooms` smallint(2) default NULL,
`bedrooms` smallint(2) default NULL,
`bathrooms` smallint(2) default NULL,
`price` float(9,2) default NULL,
PRIMARY KEY (`property_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The two mentioned form fields are simple text fields where visitors can fill in a min. price and a max. price. When both fields are indeed filled in I could handle it inside my query wit a BETWEEN statement:
WHERE price BEWTEEN 100000 AND 200000
But what would be the best way to handle a situation where neither of the fields where filled in or just one of the two, either price_from or price_to?
Thank you in advance!