how do i search an address form a group of columns from a table (zip,state,country)?
scenarioi:- 1) User enters an address into a search field. Address maybe zip,state or country
2) Now i have to take that address which may be in any orde开发者_如何学Gor or which may just contain the country, state or zip and check the database if the the results exists or not.
Any advice on this topic would be awesome
How about this one?
'SELECT * FROM table WHERE address LIKE \''. addslashes($search) .'\'
OR zip = '. (int)$search .'
OR country LIKE \''. addslashes($search) .'\''
I would do something like :
split address on space
build where clause as
WHERE zip||state||country like '%address_part_one%'
OR zip||state||country like '%address_part_two%'
and so on ...
If you have fulltext enabled for the three fields :
WHERE MATCH (zip,state,country) AGAINST ('address_part_one')
OR MATCH (zip,state,country) AGAINST ('address_part_two')
...
精彩评论