diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index 194b49128..ab7fa3e10 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -510,8 +510,19 @@ FROM ConstructionConsent if(array_key_exists("address", $filter)) { $address = FronkDB::singleton()->escape($filter["address"]); - if($address) { - $where .= " AND (vs.name LIKE '%$address%' OR vh.strasse LIKE '%$address%' OR vh.hausnummer LIKE '%$address%' OR vh.plz LIKE '%$address%' OR vh.ortschaft LIKE '%$address%' OR vh.gemeinde LIKE '%$address%')"; + if ($address) { + $address = trim($address); + $searchTerms = explode(' ', $address); + $conditions = []; + + foreach ($searchTerms as $term) { + $term = '%' . $term . '%'; + $conditions[] = "(vs.name LIKE '$term' OR vh.strasse LIKE '$term' OR vh.hausnummer LIKE '$term' OR vh.plz LIKE '$term' OR vh.ortschaft LIKE '$term' OR vh.gemeinde LIKE '$term')"; + } + + if (!empty($conditions)) { + $where .= " AND (" . implode(' AND ', $conditions) . ")"; + } } }