Is there a way I can have a single input field, called "Location" and allow the user to type in either a postcode OR town name to retrieve a business listing? eg. Bristol or BS6 6NX
Below is my table structure currently
Business: (with example data)
id - 1
name - Apples
location - bristol
postcode - bs5 6nx
Locations: (with example data)
id - 1
name - bristol
postcode - bs5 6
My current query is:
$query = "
SELECT b.id, b.name, b.category, b.thumb_picture, b.location
FROM business b
LEFT JOIN locations l ON b.location = l.name
WHERE l.name = ".$dbh->quote($userLocation)."
OR l.postcode LIKE ".$dbh->quote($userLocation."%")."
GROUP BY b.name
ORDER BY b.date DESC";
Which will only work with town names currently.
Update:
How to detect an address or a postal code in a variable
Seems to be a solution, identify if the field is a postcode or town before hand, and then perhaps have 2 queries depending on the result? One to search the postcode column and one to search town?