【发布时间】:2018-03-01 22:08:19
【问题描述】:
我有以下 PHP 代码包含 2 个 foreachs
<div class="box">
<?php
$category = ORM::for_table('cattable')->order_by_asc('order')->find_many();
foreach ($category as $cat):
$links = ORM::for_table('linktable')->order_by_asc('name')->where('idcat', $cat->id)->find_many();
?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-2" >
<table class="table table-hover table-nomargin table-condensed">
<thead>
<tr>
<td><?php echo $cat->name?></td>
</tr>
</thead>
<?php foreach ($links as $link): ?>
<tbody>
<tr class="odd gradeX">
<td><?php echo $link->name?></td>
</tr>
</tbody>
<?php endforeach;
foreach ($links as $link): ?>
<tbody>
<tr class="odd gradeX">
<?php if($link->main==7)
{
?>
<td><?php echo $link->name?></td>
<?php
}
?>
</tr>
</tbody>
<?php endforeach; ?>
</table>
</div>
<?php endforeach; ?>
</div>
问题是,我确实有很多空白,并且表格没有像我想要的那样显示..
我与 Col-lg-12 合作,我想让所有表格都像这样显示:
但它的显示如下:
我还有很多空条目
编辑:
?><?php foreach ($categorie as $cat):
$links = ORM::for_table('linktable')->order_by_asc('name')->where('idcat', $cat->id)->limit(10)->find_many();
?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-2">
<table class="table table-hover table-nomargin table-condensed">
<thead>
<tr>
<td>
<b>test</b>
</td>
</tr>
</thead>
<tbody>
<?php foreach ($links as $link): ?>
<tr>
<td>test</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
这没有区别(仍然是空格):
【问题讨论】:
-
所以基本上,你想摆脱表格中的空值吗?我无法查看您的图像,因为它们在我当前的网络上被阻止。您应该在问题中明确说明您要做什么。
-
不太确定您的问题是什么,但也许只是删除额外的
<tbody>?将它们移到foreachs(两者)之外,以便您只有其中一个 -
“我与 Col-lg-12 合作” - 你实际上与
col-lg-2合作 -
整个是 col-lg-12,表格得到 lg-2,因为我希望每个“行”有 6 个
-
我认为使用
ul比使用cols更好地实现你想要的效果
标签: php html css twitter-bootstrap html-table