@pc_oc If you use a query at each iteration only to know the total (COUNT (*) AS count) you will have major problem with performance and memory consumption, especially if the table is different from MyISAM.
You can use COUNT (*) in the second query, without needing a 3rd query:
$sql = mysql_query("SELECT DISTINCT YEAR(data) AS ano, id AS id FROM tbl_noticias GROUP BY ano");
while($row = mysql_fetch_array($sql))
{
echo "Ano: {$row['ano']}<br>";
$sql1 = mysql_query("SELECT DISTINCT MONTH(data) AS mes, COUNT(*) AS contagem, id FROM tbl_noticias WHERE YEAR(data) = '$ano' GROUP BY mes");
while ( ($row1 = mysql_fetch_array($sql1))) {
echo "Mes: {$row1['mes']} - ({$row1['contagem']})<br>";
}
}
In your example, PHP will call the COUNT (*) function 15 times, whereas in this case, it will only call 2 times.