我有以下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; ?>
这没有区别(仍为空格):
答案 0 :(得分:0)
我认为从每个类别的数据库中获得不同数量的链接,这会导致空格。尝试按类别回显您获得的链接数量:
?><?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>
// Print the number of links by category
<?php echo count($links); ?>
</td>
</tr>
</thead>
<tbody>
<?php foreach ($links as $link): ?>
<tr>
<td>test</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>