<?php
$_DATA[0]['Code'] = '1x1';
$_DATA[0]['Datum'] = '09.10.2010';
$_DATA[0]['Lehrer'] = 'Mercado';
$_DATA[0]['Fach'] = 'Spanisch';
$_DATA[0]['Vertretung'] = 'Elz';
$_DATA[0]['Klasse'] = '10a';
$_DATA[0]['Stunde'] = '1';
$_DATA[1]['Code'] = '1x1';
$_DATA[1]['Datum'] = '09.10.2010';
$_DATA[1]['Lehrer'] = 'Mercado';
$_DATA[1]['Fach'] = 'Spanisch';
$_DATA[1]['Vertretung'] = 'Sieh';
$_DATA[1]['Klasse'] = '11';
$_DATA[1]['Stunde'] = '3';
$_DATA[2]['Code'] = '1x2';
$_DATA[2]['Datum'] = '10.10.2010';
$_DATA[2]['Lehrer'] = 'Sadrawetz-Hische';
$_DATA[2]['Fach'] = 'Mathe';
$_DATA[2]['Vertretung'] = 'Graul';
$_DATA[2]['Klasse'] = '5';
$_DATA[2]['Stunde'] = '2';
$array = array();
foreach ($_DATA as $row) {
$array[$row['Datum']][$row['Stunde']][] = array('Fach' => $row['Fach'], 'Klasse' => $row['Klasse'], 'Lehrer' => $row['Lehrer'], 'Vertreter' => $row['Vertretung'] );
}
$html = '';
foreach ($array as $key_tag => $tag) {
$html .= '<table border="1" border="black">
<tbody>
<tr>
<th>Stunden</th>
<th>'.$key_tag.'</th>
</tr>';
foreach ($tag as $key_stunde => $stunde) {
$html .= '<tr>
<td>'.$key_stunde.'.</td>
<td>
<table border="1" border="black">
<tbody>
<tr>
<th>Klasse</th>
<th>Lehrer</th>
<th>Vertretung</th>
</tr>';
foreach ($stunde as $vertretung) {
$html .= '<tr>
<td>'.$vertretung['Klasse'].'</td>
<td>'.$vertretung['Lehrer'].'</td>
<td>'.$vertretung['Vertreter'].'</td>
</tr>';
}
$html .= '</tbody>
</table>
</td>
</tr>';
}
$html .= '</tbody>
</table>';
}
echo $html;