count strings in mysql

Discussion in 'PHP' started by aayybb, Jan 7, 2010.

  1. #1
    Hi,

    I have one table column with multiple string separated by space. I can make it separated by comma if that helps the task.

    I would like to count the string occurrence in the table

    ex. there might be toyota, honda, ford... in the column. The number of string in that column varies.
    I would like to know how many toyota, how many honda, how many ford, how many anything .... in the whole table. I don't know what kind of string is in the column. It can be anything.

    I need to do it in php and mysql.

    Thanks for any help or tip in advance.
     
    aayybb, Jan 7, 2010 IP
  2. luckymurari

    luckymurari Active Member

    Messages:
    629
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    90
    #2
    If, its a one time task, you can extract each row, split the string using the sstring delimiter, and then again put them in a new table, now you can do the operation using SQL commands on the table.

    If its a recurring process, its not recommended to do this as it will eat up lots of resources.
     
    luckymurari, Jan 7, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Last edited: Jan 7, 2010
    danx10, Jan 7, 2010 IP
  4. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try
    count()
    or
    substr_count()
     
    astkboy2008, Jan 7, 2010 IP