Jump to content

Archived

This topic is now archived and is closed to further replies.

jmichael68

Using REGEXP with SELECT staements matching whole words within a field

Recommended Posts

Here is the code that I have problems with...

$query22 = "SELECT '$text' from dpl WHERE $field REGEXP '[[:<:]]$text[[:>:]]'";

I'm looking to match whole words that are in variable $text.  This works when you put '[[:<:]]JOHN[[:>:]]',

is there a way to use this statement with a variable???

Share this post


Link to post
Share on other sites
This should work. Make sure $text and $field contain what you expect, and that the database connection and selection is working properly.

Share this post


Link to post
Share on other sites
if I use this:


$query22 = "SELECT * from dpl WHERE Name REGEXP '[[:<:]]$name[[:>:]]'";

I get this error message:

Parse error: parse error, unexpected '[', expecting T_STRING or T_VARIABLE or T_NUM_STRING

but my array is returning this....
SELECT * from dpl WHERE Name REGEXP '[[:<:]]RAY[[:>:]]'
SELECT * from dpl WHERE Name REGEXP '[[:<:]]VLADIMIR[[:>:]]'
SELECT * from dpl WHERE Name REGEXP '[[:<:]]MOHAMMED[[:>:]]'

when I hard code "RAY" in the statement like this...
SELECT * from dpl WHERE Name REGEXP '[[:<:]]RAY[[:>:]]'

It works???

Share this post


Link to post
Share on other sites
Ah...[tt] $name[[/tt] is being seen as an array, change it to[tt] $name\[[/tt].

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.