Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    you'll have to break your search string into words using your application language (php?)
     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 | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2009
    Thanks a bunch! That was exactly what I needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts