@pc_oc If you use a query at each iteration only to know the total (COUNT(*) AS count) you will have a big problem with performance and memory consumption, especially if the table is different from Myisam.
You can use COUNT(*) in the second query without the need for 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 this will only call 2 times.
however I managed to reach the result with the reply I put. anyway thank you!
– pc_oc