我已经设法从数据库创建两个数组,一个用于table_headers,如下所示
$tb_headers=array('010','011','012','013','014','015','016');
并且还从数据库生成表_data的其他数组,如下所示
$tb_data=array(
array('011','013','014','015'),
array('010','012','014','015','016'),
array('010','011','013','016'),
array('010','011','012','013','014','015','016')
);
我如何生成这种格式的表?
th 010 | 011 | 012| 013| 014 | 015 | 016
row1 - | 011 | - | 013| 014 | 015 | -
row2 010 | - | 012 | - | 014 | 015 | 016
row3 010 | 011 | - | 013| - | - | 016
row4 010 | 011 | 012 | 013| 014 | 015 | 016
I have tried to write this script which is not working as expected
<table style="width:50%;" border="1">
<tr>
<?php
foreach ($tb_headers as $key => $value) {
echo '<th>'.$value.'</th>';
}
echo '</tr>';
foreach ($tb_headers as $key => $data) {
echo '<tr>';
if(!empty($tb_data[$key])&& $tb_data[$key]==$data ){
echo '<td>'.$tb_data[$key].'</td>';
}else{
echo '<td>-</td>';
}
echo '</tr>';
}
?>
</table>