Good afternoon Guys, I'm having a problem with grouping content in the following structure:
Month
Day
In the query I have two tables, "schedule" and "user". In the calendar table I have a field of type "date" that "should" group the content.
$data = date("Y-m-d");
$mes_atual = '';
$dia_atual = '';
$tbody = '';
$dados = Connection::select("Select agenda.id,u.nome as
nome_pessoa,agenda.hora,agenda.compromisso,agenda.local,agenda.pessoa,
agenda.data,DAYNAME(NOW()) AS dia, year(NOW()) AS ano,
MONTHNAME(NOW()) AS mes from agenda inner join users u on
(agenda.pessoa = u.id) order by mes asc, dia asc, hora asc");
foreach ($dados as $reg) {
if ($mes_atual != $reg['mes']) {
$tbody.= '<tr><td colspan=4><h3>' . $reg['mes'] . '</h3></td></tr>';
$mes_atual = $reg['mes'];
}
if ($dia_atual != $reg['dia']) {
$tbody .= '<tr><td colspan=4><h5>' . $reg['dia'] . ', ' . $reg['dia'] . '</h5></td></tr>
<tr>
<td style="width:10%;"><b>Hora</b></td>
<td style="width:40%;"><b>Compromisso</b></td>
<td style="width:25%;"><b>Local</b></td>
<td style="width:25%;"><b>Pessoas</b></td>
</tr>';
$dia_atual = $reg['dia'];
}
$tbody .= '
<tr>
<td style="width:10%;">' . $reg['hora'] . '</td>
<td style="width:40%;">' . $reg['compromisso'] . '</td>
<td style="width:25%;">' . $reg['local'] . '</td>
<td style="width:25%;">' . $reg['nome_pessoa'] . '</td>
</tr>
';
}
$html = str_replace('#TBODY#', $tbody, $html);
return $html;
The weird thing is that if I do not match the "schedule" and "user" tables, clusters work.