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???
Link to comment
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???
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.