Good afternoon, I need to group a list by month, I use the field of type date in the table. I tried to do it, but he repeats the month each had on the list. See my code.
$dados = Connection::select("SELECT *,date_format('data','%d/%m/%y') as 'data_formatada', date_format('data','%M') as mes FROM 'noticias' where mes =' . $mes . '");
$tbody = '';
foreach ($dados as $reg) {
$tbody .=
'
<thead>' . $reg['mes'] . '</thead>
<div class="medium-3 columns">
<img src="' . $reg['imagem'] . '" width="155px" class="thumbnail" title="' . $reg['titulo'] . '"></img>
</div>
<div class="medium-9 columns">
<a style="color: #008000;" href="' . URL . 'noticias/exibir-id/' . $reg['id'] . '">' . $reg['titulo'] . '</a><br>
<small class="subheader">Por:<b> ' . $reg['por'] . '</b><br>Data: ' . $reg['data_formatada'] . '</small><br>
<small class="subheader">' . $reg['titulo'] . '</small>
</div><hr>
';
}
$html = str_replace('#TBODY#', $tbody, $html);
return $html;
break;
See the image below as it stands. If anyone can help.
Iwouldlikeittolooklikethis: