I'm building a list of how many times a distinct publication is listed in my database. I want to include a count of how many times each publication is listed. I'm pretty sure I need to use COUNT in my SELECT statement somewhere, but am having a hard time figuring out how.
<?php
$sql = "SELECT DISTINCT publication FROM $table ORDER BY source ASC";
$result = mysql_query ($sql) or die (mysql_error());
$numrows = mysql_num_rows ($result);
while ($myrow = mysql_fetch_array($result))
{
printf ("%s", $myrow["publication"]);
}
?>
I want the result to render like this:
Publication1 (23)
Publication2 (1)
Publication3 (45)
Probably printed like:
printf ("%s (%s)", $myrow["publication"], $myrow["publicationCount"]);
Thanks!