Jump to content

Using REGEXP with SELECT staements matching whole words within a field


jmichael68

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???
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???

Archived

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

×
×
  • Create New...

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.