Reputation: 165
I have a search form containing both city and postcode fields. The search is queries a mysql database and returns relevant results.
To make things easier for the user is it possible to combine these two and allow either cities or postcodes to be entered into the field?
Thanks
Upvotes: 0
Views: 297
Reputation: 2911
Use is_numeric()
function (or regexp) to figure out which type of data you have in request (city name or postcode).
Upvotes: 1
Reputation: 761
Yes. A city name is probably not starting with numbers, so use that to filter, with a regular expression, and compare to the proper field.
Upvotes: 0
Reputation: 360562
It'd just mean an 'or' clause in your query, something along the lines of:
SELECT ...
WHERE city='$formfield' OR postcode='$formfield'
Upvotes: 4