SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    find table row where field is fully contained within searchstring

    php/mysql: How can i find the table row where the field is exactly matched/contained within the search string?

    eg

    search string: the cat sat on the mat
    my table field is: on the mat

    Have been trying field LIKE '%...%' but thats not quite right?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can look for all substrings broken up at spaces

    Code:
    WHERE field IN ('the cat sat on the mat', 'the cat sat on the', 'the cat sat on', 'the cat sat', 'the cat', 'the', 'cat sat on the mat', 'cat sat on the', 'cat sat on', 'cat sat', 'cat', 'sat on the mat', 'sat on the', 'sat on', 'sat', 'on the mat', 'on the', 'on', 'the mat', 'the')
    The order I gave should give you the algorithm for quickly generating the list.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,265
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    WHERE '$searchstring' LIKE CONCAT('%',table.column,'%')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats worked a treat thanks r937


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
  •