![]() |
MySQL select 10 words before match - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: MySQL select 10 words before match (/showthread.php?tid=22435) |
MySQL select 10 words before match - El Forum - 09-09-2009 [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 MySQL select 10 words before match - El Forum - 09-09-2009 [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/regexp.html#operator_regexp be warned that if you have a lot of these kinds of queries it'll be a pretty big hit to DB performance. MySQL select 10 words before match - El Forum - 09-09-2009 [eluser]hugle[/eluser] thank you mate, I'll take a look into that ![]() |