$brand = "111"; $result = mysql_query("SELECT * FROM inven WHERE Stock_ ='/([0-9]{3}) . '-' . $brand . '-' . ([0-9]{5})/'") This isn't working I want it to pull a field that looks like 001-XXX-92415 XXX is defined about
What's the lesson here boys and girls? That's right: Data normalization is important. A stitch in time saves having to compose complex queries. Sounds like your 'Stock_' field contains multiple signficant pieces of data (i.e. 3 numbers before the first dash, numbers between the dashes, numbers after the second dash). It shouldn't. Each significant piece of data should have its own field in your database which will make running queries like this easier. This query should work on your data until you properly normalize it: SELECT * FROM inven WHERE Stock_ LIKE '%-'.$brand.'-%';