SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Simple Search

  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Search

    I am developing a simple keyword search using php and mysql and I am facing problem while using "AND" and "PARENTHESIS" advanced search where user inputs the query. I developed following sql query:
    Select * from Page LEFT JOIN Page_Tag LEFT JOIN Tag where((name="events" and name="news") or name="local")

    I am not getting the answer of the "and" operation whereas "or" operation works properly.

    And in parenthesis search, how do i parse input.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by dipika View Post
    name="events" and name="news"
    that's never going to be true, ever (and i think you know this already, right?)

    the same column value cannot possibly be equal to two different things at the same time

    you are going to have to re-think your strategy
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try to make an inner join ad this might solve your problem

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,139
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Looks like you want all the pages tagged either (events and news) or just local. Is that correct? Posting the create tables would help.
    The only code I hate more than my own is everyone else's.

  5. #5
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    Looks like you want all the pages tagged either (events and news) or just local. Is that correct? Posting the create tables would help.
    Yes, that is what I want.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,139
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    From your query I can only grasp that there is a column named name inside the Page_Tag table which is just about worthless. The create tables are needed.

    Edit: Besides that every row of the Page table is being joined on every row of the Page_Tag table, which I don't believe is what your after. I would assume where is something like page_id inside the table Page_Tag table that relates a tag to a page. If so please clearly define which column that is. Also it might be worth considering using a m:n relationship here rather then a 1:m relationship, unless there is a table called Tag somewhere just not part of the query.
    The only code I hate more than my own is everyone else's.


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
  •