SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: MySQL Query

  1. #1
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query

    Say I have the current query:

    Code:
    SELECT * FROM `table` WHERE `name` IN ('spy', 'next', 'door')
    That searches to see if there is a field with the name spy, the name next, or the name door right?

    I want to see if there is any names CONTAINING the words: spy, next and door.

    For example: Private Spy - the word spy would come up with that.
    For example: Next Home - the word next would come up with that.
    For example: The Door Mat - the word door would come up with that.

    ALSO

    If there is a result called Spy Next Door, it only comes up with 1 result.

    Help please? Is it possible what I'm asking?
    :-)

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
     WHERE name LIKE '%spy%'
        OR name LIKE '%next%'
        OR name LIKE '%door%'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't understand your mean?

  4. #4
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
     WHERE name LIKE '%spy%'
        OR name LIKE '%next%'
        OR name LIKE '%door%'
    I know LIKE works for that, but my script won't work like that, isn't there another way?
    :-)

  5. #5
    SitePoint Enthusiast DidUSayScript's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The 'where clause' by r937 does exatly what you asked for, unless I am missing something.
    ______________________
    Enjoying life is not about what you get from it ....
    ...... but how you perceive what you get

    www.jerilimited.co.uk

  6. #6
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.sitepoint.com/forums/showthread.php?t=665589

    I was aiming to use IN and just use what I had coded as posted recently on the topic above.

    But now it searches for the exact word entered, not a LIKE %$str% query like I am looking for, so I'm going to have to redo it.
    :-)

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Kyle R View Post
    but my script won't work like that, isn't there another way?
    yes, get a new script
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Enthusiast DidUSayScript's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With your sample on the other thread if you use $str - you can do the following
    PHP Code:
    $whereclause "where name LIKE '%".implode("%' OR name LIKE '%",str_word_count($str,1,'1234567890'))."%'"
    ______________________
    Enjoying life is not about what you get from it ....
    ...... but how you perceive what you get

    www.jerilimited.co.uk


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
  •