If you create a class representing the property table, you can define a static array in the class detailing each field name and corresponding data type.
On the front end, each search field should correspond to the column name in the database, so the $_REQUEST array keys will match the column names.
After this, iterate through your search array, checking each variable exists in your class field definition array, and add it onto the search query.
Below is a very simplified example class which will hopefully give you the idea.
class Property () {
// search parameters come from $values_array
// each search field should correspond to the $field_definitions key
public function search($values_array = null) {
// populate the values array. Using this method meads you can pass an array directly
// into the search function, or you can rely on the $_REQUEST
$values_array = self::getValuesArray($values_array);
// setup the initial query
$query = "SELECT * FROM properties";
// set our initial join string
$join = "WHERE";
// loop each of our search values
foreach ($values_array as $field=>$value) {
// check the search key exists in our table definition and it's not empty
if (array_key_exists($field_definitions, self::$fields) && !empty($value)) {
// switch the datatype for the field so we can set the appropriate query string
switch (self::$field_definitions[$field]) {
case 'int':
$query .= "$join $field = {$value} ";
$join = "AND";
break;
default:
$query .= "$join $field = '%{$value}%' ";
$join = "AND";
break;
}
}
}
// now execute the query...
$results = mysql_query($query);
// do something to process the results and then return
return $results;
}
// basic function to grab our values from $_REQUEST if passed an empty array
private function getValuesArray($values_array = null) {
$values_array = (!empty($values_array)) ? $values_array : $_REQUEST;
return $values_array;
}
// variable containing all available fields in table and corresponding datatype
public static $field_definitions =
array( 'number'=>'int',
'street'=>'string',
'locality'=>'string',
'townland'=>'string',
'town'=>'string',
'postcode'=>'string'
);
}