Results 1 to 2 of 2
Feb 24, 2009, 06:35 #1
- Join Date
- Apr 2004
- Burlington, VT .. USA
- 0 Post(s)
- 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
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..
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
$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??
Feb 24, 2009, 06:43 #2
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_locateGuido - Community Team Leader
The 2013 SitePoint Awards - Nominate your heroes now!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget