If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Searching for User's Location

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-09, 23:37
sdsportsfanatic sdsportsfanatic is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
Searching for User's Location

I have a site that store's different user's locations. I have fields for city, state, and neighborhood. I need to create a search feature that takes one input query and searches through these three fields. Here is an example:

Search for "Encinitas California"

Possible results:
City - Encinitas
State - California
Neighborhood - Cardiff

City - San Diego
State - California
Neighborhood - Encinitas

All query words must be contained in at least one of the three fields.

I cannot figure out how this could be done. I thought about creating a fourth field combining all the data as "Encinitas California San Diego" and having the query reference that field using "like", but it did not work how I needed it to.

Is there a way to accomplish this?

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 00:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you'll have to break your search string into words using your application language (php?)
Code:
 WHERE ( city = '$word1'
      OR state = '$word1'
      OR neighborhood = '$word1'
       )
   AND ( city = '$word2'
      OR state = '$word2'
      OR neighborhood = '$word2'
       )
generate as many of these as you have words in the search string
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-12-09, 02:02
sdsportsfanatic sdsportsfanatic is offline
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks a bunch! That was exactly what I needed.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On