php - foreach()表有空白吗?

标签 php html css twitter-bootstrap html-table

我有以下 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 一起工作,我想让所有的表都像这样显示:img1

但它显示如下: img2 img3

我还有很多空条目

编辑:

                        ?><?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; ?>

这没有区别(仍然是空白):

img4

最佳答案

我认为您从数据库中为每个类别获得了不同数量的链接,这导致了空白。尝试按类别回应您获得的链接数:

                        ?><?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; ?>

关于php - foreach()表有空白吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46328959/

相关文章:

php - 在 apache tomcat 服务器上使用 CakePHP

html - 结果显示在两行?

html - 仅CSS的砌体布局

javascript - 如何使用 angular 或 javascript 根据 true/false 返回值在 html 中显示值?

html - 更改输入时的蓝色发光(复选框)(bootstrap 4)

php - laravel 5 仅根路径有效

php - 如何使用 Sag 从 Apache CouchDB 文档获取附件?

css - * :before, *的目的:在没有内容属性的规则之后

html - navbar-brand 文字流出navbar

php - 如何在自定义 WP 插件安装中创建 MySQL 触发器