【发布时间】:2018-12-24 01:53:16
【问题描述】:
我的数据库中有 67 个类别,我使用 $categories 调用这些类别。
我想将它们全部动态打印到表格中。
到目前为止我所尝试的:
<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$countCat = round(count($categories) / 10); // 67 / 10 = 6. 7 | with round = 7
$i = 0;
foreach ($categories as $key => $value) {
++$i;
if ($i >= 10) {
?>
<td class="mdl-data-table__cell--non-numeric">
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="<?php print $value['catID']; ?>">
<input type="checkbox" id="<?php print $value['catID']; ?>" class="mdl-checkbox__input">
<span class="mdl-checkbox__label"><?php print $value['categoryNames']; ?></span>
</label>
</td>
<?php
}
if ($i >= 20) { ?>
<td class="mdl-data-table__cell--non-numeric">
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="<?php print $value['catID']; ?>">
<input type="checkbox" id="<?php print $value['catID']; ?>" class="mdl-checkbox__input">
<span class="mdl-checkbox__label"><?php print $value['categoryNames']; ?></span>
</label>
</td>
</tr>
<?php
}
}
?>
</tbody>
即使使用 $i 停止并创建下一行,它也只输出 1 行?
我希望表格有 9 行,如果有 67 个或更多类别,它应该自动计算必须创建多少列。
任何帮助将不胜感激。
【问题讨论】:
-
您缺少行的
标记? -
试过还是不行。
标签: php mysql html-table