... orderby date
$lastDate = null;
foreach ($posts as $post) {
if ( $post->date !== $lastDate ) {
echo $post->date;
$lastDate = $post->date;
}
// остальной вывод данных
}
SELECT * FROM `table_name` group by `id`,`date`