我有这个代码,用于构建一个表,其中每个建筑物将创建一个新表,其中包含标题标记,其中包含建筑物名称,并使用也具有tr的tbody将每个人和计算机分组到各自的扇区中在每个小组之前使用其名称。 类似的东西:
<table class="table table-bordered table-condensed">
<caption>Building 1</caption>
<tbody>
<tr class="title"><td>Sector1</td></tr>
<tr><td>Person 1</td></tr>
<tr><td>Person 2</td></tr>
<tr><td>Person 3</td></tr>
</tbody>
<tbody>
<tr class="title"><td>Sector2</td></tr>
<tr><td>Person 1</td></tr>
<tr><td>Person 2</td></tr>
<tr><td>Person 3</td></tr>
</tbody>
</table>
<table class="table table-bordered table-condensed">
<caption>Building 2</caption>
<tbody>
<tr class="title"><td>Sector1</td></tr>
<tr><td>Person 1</td></tr>
<tr><td>Person 2</td></tr>
<tr><td>Person 3</td></tr>
</tbody>
</table>
我开始(坚持)这个:
if ($STH->fetch() > 0):
$sector;
$building;
$tbodyf = "<tbody><tr class='primary'><th colspan='2'>Building: %s</th></tr>\n";
$tbodytitle = "\n<tr class='info'>\n<td colspan='2'><b>Sector: %s</b></td>\n</tr>\n";
$tbodytr = "<tr><td>%s</td><td>%s</td></tr>\n";
while ($row = $STH->fetch()) {
if ($row->building !== $building) {
$building = $row->building;
printf($tbodyf, $building);
}
if ($row->sector !== $sector) {
$sector = $row->sector;
printf($tbodytitle, $sector);
}
printf($tbodytr, $row->person, $row->hostname);
}
else:
echo '<h3>Nothing to see!</h3>';
endif;