Генерация Таблиц Html Средствам Php

framd

New member
21.12.2014
1
0
#1
Дан вот такой массив:
PHP:
Array
(
[0] => Array
(
[name_channel] => Первый
[image_channel] => images/logo_channels/P1-1.png
[start_time] => 2014-12-26 07:00:00
[name_telecast] => От праздника к празднику
)

[1] => Array
(
[name_channel] => Первый
[image_channel] => images/logo_channels/P1-1.png
[start_time] => 2014-12-26 08:00:00
[name_telecast] => "V" значит Вендетта
)

[2] => Array
(
[name_channel] => Первый
[image_channel] => images/logo_channels/P1-1.png
[start_time] => 2014-12-26 09:00:00
[name_telecast] => Без следа
)

[3] => Array
(
[name_channel] => Первый
[image_channel] => images/logo_channels/P1-1.png
[start_time] => 2014-12-26 10:00:00
[name_telecast] => Фарго
)

[4] => Array
(
[name_channel] => Звезда
[image_channel] => images/logo_channels/P1-5.png
[start_time] => 2014-12-19 12:00:00
[name_telecast] => Фарго
)

)

Необходимо сгенерировать такие таблицы:
HTML:
<table border="1">
<tr>
<td>logo</td>
<td>name_channel</td>
</tr>
<tr>
<td>start_time</td>
<td>name_telecast</td>
</tr>
<tr>
<td>start_time</td>
<td>name_telecast</td>
</tr>
<tr>
<td>start_time</td>
<td>name_telecast</td>
</tr>
</table>
 

1ive

Well-known member
12.09.2010
621
1
#2
Если передачи с одним каналом идут в массиве друг за другом, а не вперемешку с другими, то можно сделать так:
PHP:
<?php
echo '<table border="1">';
$chName = "";

foreach($array as $one){
if($chName != $one['name_channel']){
echo "<tr>
<td><img src=\"".$one['image_channel']."\" /></td>
<td>".$one['name_channel']."</td>
</tr>";
$chName = $one['name_channel'];
}
echo "<tr>
<td>".$one['start_time']."</td>
<td>".$one['name_telecast']."</td>
</tr>";
}

echo '</table>';
?>
Не проверял, но работать должно.