I'v got this small PHP/MySQL problem which for some reason i just can't seem to get past. I've got this table with a field called for example "topic" and for each entry there may be different topics or the same topics e.g. id: topics: 1 fish 2 fish 3 beans 4 bread 5 bread What i want to do is to count up the occurrences of each entry, but if they are the same then print them like this them like this: fish 2 beans 1 bread 2 Sounds simple enough? if i've explained it at all well, but for some reason i cant seem to get it lol. I would show what code i have got, but its messy and i've changed it about so much that it probably looks silly Any help would be appreciated?
$query = "SELECT topics, COUNT(topics) FROM topic GROUP BY topics"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['topics']." : ".$row['COUNT(name)']; echo "<br />"; } PHP: