I have MySQL database fields that can contain up to 3 values, separated by a comma (Red,Blue,Yellow). I would like to count how many times each value appears. So, the results would be Red 4, Blue 3, Yellow 2.
id | color
1 | Red,Blue
2 | Red,Blue
3 | Red,Yellow
4 | Red,Blue,Yellow
It seems like I would have to loop through each row, exploding the string; then loop through the results to count the values. But I'm not even sure where to begin doing that.
$result = mysql_query("SELECT color FROM cars");
$row = mysql_fecth_array($result);
$count = count($favColors);