SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Tennessee
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query Help - Where Clause

    I have a forms page that will allow a user to select up to 11 criteria the can select 1 or more up to 11. They do not have to select all 11.



    I then have the following query:



    mysql_select_db($database_conndb1, $conndb1);

    $query_rsName = sprintf("SELECT DISTINCT table1.search_id, table1.search1, table1.search2, table1.search3, table1.search4, table1.search5, table1.search6, table1.search7, table1.search8, table1.search9, table1.search10, table1.search11, table1.search12, table1.search13, table1.search14, table1.search15, table1.search16, table2.search_id FROM table1, table2 WHERE table2.criteria1 = %s OR table2.criteria2 = %s OR table2.criteria3 = %s OR table2.criteria4 = %s OR table2.critertia5 = %s OR table2.criteria6 = %s OR table2.criteria7 = %s OR FIND_IN_SET(%s, table2.criteria8) OR table2.criteria9 = %s OR table2.criteria10 = %s OR table2.criteria11 = %s AND table1.search_id = table2.search_id ORDER BY table1.search2 DESC", GetSQLValueString($search1_rsName, "text"),GetSQLValueString($search2_rsName, "text"),GetSQLValueString($search3_rsName, "text"),GetSQLValueString($search4_rsName, "text"),GetSQLValueString($search5_rsName, "text"),GetSQLValueString($search6_rsName, "text"),GetSQLValueString($search7_rsName, "text"),GetSQLValueString($search8_rsName, "text"),GetSQLValueString($search9_rsName, "text"),GetSQLValueString($search10_rsName, "text"),GetSQLValueString($search11_rsName, "text"));

    However, when the query is ran, it pulls all records not just the ones based on the search criteria. Now, if I change the OR to AND and select all 11, it works as it should. Thus, it has something to do with OR operand. However, I cannot figure out what is wrong. What operand can I use besides OR that will allow this to work to allow the searcher to select 1, 2, 3 or more criteria?

  2. #2
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Tennessee
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found an answer - had to move the parenthesis around the entire where clause to include all the OR clauses in the single parenthesis.


Tags for this Thread

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
  •