Tuesday, 15 March 2011

Unique value count of comma separated field (PHP - MySQL) -


I have mysql table that looks like this:

  ID location interest 1 location 1a, b, c 2 place2 c, d, e 3 place1 a, e 4 place2 f 5 place2 f 6 place3 g, h   

give me unique "location" and "interest" values Need to get I ordered according to the order. Therefore, the output for "location" will be

  place2 (3) location1 (2) position 3 (1)   

then, "for interest Output "" (2) C (2) E (2) F (2) B (1) D (1) g (1) H (1)

  / Pre > 

Is there a way to do this in PHP-Mysql?

Therefore, by now I am able to get simple column data

  SELECT place, COUNT Order (*) DESC at the place by the group respectively (*) as the number (*) DISC    

As for catching up with MySQL ARL It is better not to create a new table like this:

  interest_id interest_name 1 a 2b   

And to have another relationship:

  pk id interest_id 1 1 2 2 2   

This ID is the ID of records in your main table.

html>

No comments:

Post a Comment