Haribo83
Haribo83

Reputation: 165

City or post code search in same field

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

Answers (3)

KomarSerjio
KomarSerjio

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

noinstance
noinstance

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

Marc B
Marc B

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

Related Questions