Pulling wont work - Urgent

Discussion in 'MySQL' started by hotfaps, Mar 23, 2010.

  1. #1
    $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
     
    hotfaps, Mar 23, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    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.'-%';
     
    plog, Mar 23, 2010 IP