Welcome Guest, Not a member yet? Register   Sign In
MySQL select 10 words before match
#1

[eluser]hugle[/eluser]
Hello everyone,

for example I'm searching a string from MySQL, for example:

`name` field in mysql is: 'hello everyone here. it's time to code now';

what I want to do, is to get 2 words before and 2 words after match, so the query:

SELECT `id` FROM `name` WHERE `name` LIKE '%here%';

would return me:
'hello everyone here. it's time'

is doable in mysql? or maybe I can do it it with PHP, somehow I can't find any decent example...

Thank you,
Jaroslav
#2

[eluser]brianw1975[/eluser]
i think you want to look into using REGEXP in your MYSQL query

check out http://dev.mysql.com/doc/refman/5.0/en/r...tor_regexp

be warned that if you have a lot of these kinds of queries it'll be a pretty big hit to DB performance.
#3

[eluser]hugle[/eluser]
thank you mate, I'll take a look into that Smile!




Theme © iAndrew 2016 - Forum software by © MyBB