SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Location
    UK
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple query search with ALL functionality

    Hi all,

    This is probably a really dumb question, but it's been bugging the hell out of me.

    I'm setting up a multisearch option on a site that works fine if I complete each of the parameters.

    For example:

    I have 3 fields to choose from, Country, County and City.

    As long as I choose one entry from each I'll get the expected results.

    However, I need to be able to have the option to choose ALL from any/all of the drop down lists and return the relevant results.

    Currently, the values are being passed by the URL which stops me from using wildcards.

    Can anyone shed some light as to how to achieve this?

    Thanks in advance.

    Regards

    Paul

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Usually I use some sentinel value for ALL, like -1
    For example when $_GET['country'] is set to -1 I don't include the country in the WHERE clause, automatically selecting all countries. Or, to put it differently, not excluding any countries

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    it's okay to pass in a value of "all" for a particular option, but when you are construction the query, test the value passed in, and it it's "all" then omit the WHERE condition for that parameter

    for example, if the parameters passed in for country/county/city are xx/yyy/all then you would run
    Code:
    WHERE country = 'xx'
       AND county = 'yyy'
    -- no filter on city
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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