My search functionality is not great on my site and I could do with some advice on improving this.
Essentially my database holds the following information about each accommodation business.
Btw this is a UK based site.
So lets say we have the address
Crown Hill (address1)
West Buckland (address2)
TA21 9SZ (postcode)
My site has a search form allowing a user to type in a search location.
So for example, someone may type in "West Buckland, Somerset"
Currently in my code, I explode the location that the user types in, into an array then use code like the following which kind of works if their search location is only one element e.g "West Buckland"
I am not currently checking against address1 as have assumed this is just a street name - which I know will not always be the case:(
$loc_array = explode(",", urldecode($this->loc));
$sql = "SELECT ? FROM accommodation WHERE (accommodation.address2 LIKE '%".$db->prepare($loc_array)."%' OR accommodation.townCity LIKE '%".$db->prepare
($loc_array)."%' OR accommodation.county LIKE '%".$db->prepare($loc_array)."%' OR accommodation.postcode LIKE '%".$db->prepare($loc_array)."%')";
My code doesn't work if someone enters something like
"West Buckland, Somerset"
Any advice how to put this query together much appreciated. I cannot think of any way of doing it efficiently - my only thoughts are using a very long set of "AND" and "OR" conditionals which I am sure would be really inefficient.
Thanks in advance