I need to translate my database result into a nice HTML table by using dimensional array. I know that this is a very conditional situation.
I am using CodeIgniter and already have some data. I tried to extract the database result and make new arrays format. Now I am confused on how to format it nicely into HTML table.
$schedule = [];
foreach($this->data['jadwal_kelas'] AS $row)
{
$schedule['class_name'][$row->class_name]['time'][$row->start.'-'.$row->end] = ['room' => $row->room, 'mentor_code' => $row->mentor_code];
}
And here the result using print_r
<pre>Array
(
[class_name] => Array
(
[E-1] => Array
(
[time] => Array
(
[07:30:00-08:30:00] => Array
(
[room] => A
[mentor_code] => TPA-1
)
[08:30:00-09:30:00] => Array
(
[room] => A
[mentor_code] => TPA-1
)
[10:00:00-11:00:00] => Array
(
[room] => A
[mentor_code] => FIS-1
)
[11:00:00-12:00:00] => Array
(
[room] => A
[mentor_code] => FIS-1
)
)
)
[E-2] => Array
(
[time] => Array
(
[07:30:00-08:30:00] => Array
(
[room] => D
[mentor_code] => FIS-1
)
[08:30:00-09:30:00] => Array
(
[room] => D
[mentor_code] => FIS-1
)
[10:00:00-11:00:00] => Array
(
[room] => D
[mentor_code] => BIO-1
)
[11:00:00-12:00:00] => Array
(
[room] => D
[mentor_code] => BIO-1
)
)
)
)
)
...
</pre>
I want the HTML table looks like below :
Time | E1 | E2 | E3 |
-------------|-------|--------|--------|
07:30-08:30 | TPA-1 | FIS-1 | |
08:30-09:30 | TPA-1 | FIS-1 | |
10:00-11:00 | FIS-1 | BIO-1 | MATH-1 |
11:00-12:00 | FIS-1 | BIO-1 | MATH-1 |
...
I don't know how to loop
through the arrays to create a table like above. If someone here could point me in the right direction, would be much appreciated. Thank you.