mysql Substring query

Discussion in 'PHP' started by junandya, Dec 20, 2007.

  1. #1
    Hi,

    I have some problem with mysql query,.. i have a field in my mysql which called with:

    software: varchar(250)

    this field is information about software that member capable in. It can be inserted by more than one value which is seperated by comma. the Values is number from 1 until 25. this data bellow is for example:

    id --- software
    1 --- 2,3,13
    2 --- 6,12,14,15
    3 --- 3,4,7,9,13,23,24
    4 --- 1,13
    5 --- 2
    6 --- 10,11


    my question: what is the query substring script to find a value in a data that containing value (x), for example i want to know which rows that containing value 13.

    Thank you very much
     
    junandya, Dec 20, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Barti1987, Dec 20, 2007 IP
  3. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #3
    software LIKE 'x,%'-->x,5,6,25
    software LIKE '%,x,%'--->5,6,x,25
    software LIKE '%,x'--->5,6,25,x
     
    coderbari, Dec 20, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    This won't work if x is only in the table, should be:

    
    SELECT * FROM `tableName` WHERE `software` LIKE '$x,%' OR `software` LIKE '%,$x,%' OR `software` LIKE '%,$x' OR `software` = '$x'
    
    PHP:
    Also you need the field software to be a "fullindex".

    Peace,
     
    Barti1987, Dec 21, 2007 IP