MySQL gurus in here now please.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nookster
    Confirmed IT Professional
    • Nov 2005
    • 3744

    #1

    MySQL gurus in here now please.

    So I've been trying to get a damn search option to work with one of my mainstream projects for the past day or so but it's just not working. Here's the query I'm using:
    $trysrch = @mysql_query("select * from table_name where item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch' && area = '$place' order by item_name asc");
    Looks fine right? According to documentation this should work. Well, all of the selects for the OR (||) work, but once it gets to the AND part it seems to just overlook it and doesn't do anything. It does finish successfully (as in no errors) but it doesn't use the AND part (doesn't further narrow the results by executing the actual logic).
    My questions: Why doesn't this work? What am I doing wrong if it's wrong?
    This has been frustrating the shit out of me.
    Thanks to all who will be kind enough to reply.
    The Best Affiliate Software, Ever.
  • tical
    Confirmed User
    • Feb 2002
    • 6504

    #2
    put the OR parts in parenthesis, i think that should fix it

    $trysrch = @mysql_query("select * from table_name where (item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch') && area = '$place' order by item_name asc");
    112.020.756

    Comment

    • WarChild
      Let slip the dogs of war.
      • Jan 2003
      • 17263

      #3
      You don't understand how "OR" works. Read more grasshopper, read more.
      .

      Comment

      • WarChild
        Let slip the dogs of war.
        • Jan 2003
        • 17263

        #4
        I believe your statement is being evaluated like this:

        item_name like '$srch'
        OR
        item_name2 like '$srch'
        OR
        item_name3 like '$srch' AND area = '$place' order by item_name asc
        .

        Comment

        • Nookster
          Confirmed IT Professional
          • Nov 2005
          • 3744

          #5
          Originally posted by tical
          put the OR parts in parenthesis, i think that should fix it

          $trysrch = @mysql_query("select * from table_name where (item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch') && area = '$place' order by item_name asc");
          Thank you very much. It works great now. Guess I should read more.
          The Best Affiliate Software, Ever.

          Comment

          • BT
            Confirmed User
            • Apr 2002
            • 6481

            #6
            go fuck your self

            IS Prime Hosting Bald Head Shine "BT" The American Dream, baby!
            " THE HOST WITH THE MOST!"



            My ICQ 122994792

            Comment

            Working...