SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast urbanformula's Avatar
    Join Date
    Apr 2004
    Location
    Burlington, VT .. USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT SUBSTRING around a search term?

    so i hope i can explain this well for everyone..

    i have a search system that searches for a word a user inputs...
    now i can display all the results based on the pages

    ex:

    1. this page has that word
    2.this page has that word

    and so on... but id like to add a sentence from the page that contains that word..

    ex:

    1. this page has the word
    and this is some text that has the word and this is some text after the word

    i hope that made sense, what im trying to do is grab text around the the search term which in this example is word, but when using the sub string select all it does is grab the characters i define

    ex:

    $query = "SELECT SUBSTRING(page_content,100,180) AS 'search_string' FROM pages WHERE page_content LIKE '%$trimmed%'";

    is there away of grabing the surounding text??

    thanks!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    This is a MySQL question, not a PHP one.
    Anyway, you might try with a combination of SUBSTRING and for example LOCATE:
    http://dev.mysql.com/doc/refman/5.1/...unction_locate


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
  •