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??
This is a MySQL question, not a PHP one.
Anyway, you might try with a combination of SUBSTRING and for example LOCATE: