labiere Posted August 7, 2008 Share Posted August 7, 2008 I am trying to select a subset of rows from a table based on a text pattern. My table column, labeled "id", has entries like this: xx2 xx38 xxy2 (These items are always made up of 1 or more letters followed by one or more numbers) I have defined a PHP variable $prefix="xx" I want to perform a query that will select the two "xx" rows, but not the "xxy" row. When I try the query like this, I get all three rows back, as I would expect: // Performing SQL query $query2 = "SELECT * FROM table WHERE id REGEXP '^$prefix'"; I thought this change would give me rows that start with "xx" immediately followed by a digit: // Performing SQL query $query2 = "SELECT * FROM table WHERE id REGEXP '^$prefix[0-9]'"; .. What I get with that change is an error message: Parse error: syntax error, unexpected '-', expecting ']' Been banging my head over it for a while now.. Any ideas? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 7, 2008 Share Posted August 7, 2008 $prefix[0-9] is being interpreted as an array; use ${prefix}[0-9]. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.