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? Link to comment https://forums.phpfreaks.com/topic/118674-solved-where-expr-regexp-pat-creating-unexpected-error/ 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]. Link to comment https://forums.phpfreaks.com/topic/118674-solved-where-expr-regexp-pat-creating-unexpected-error/#findComment-611005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.