从foreach循环限制表中显示的列数

时间:2015-11-05 15:59:47

标签: php html css forms html-table

我有一个Loop,它将数据输出到html表格和表格中。我如何限制它显示的列数,我想这样做的原因是因为我的空间有限,循环可能会运行1000次甚至更多,具体取决于用户。

我想将列限制为6,所以如果循环运行6次,我希望它为另外6列创建一个新行并再次重复。

<form method="POST" action="script.php">
<table><tr>
<td><input type="checkbox" name="itemSelect[]" class="itemSelect" value="<?php echo $id; ?>" /></td>
<td>
<div class="item-box" data-id="<?php echo $id; ?>">
    <img src="<?php echo $value['image_inventory']; ?>.png">
    <div id="rarity">
       <p> <?php
                if (!isset($value['item_rarity'])) {
                    $rarity = "common";
                     echo $rarity;
                } else {
                    $rarity = $value['item_rarity'];
                     echo $rarity;
                }
            ?> </p>
    </div>

</div></td>
 </tr> </table>
 <?php
}

 }
?> 
 </table>
<button type="Submit">
    Send Trade Offer
</button>

1 个答案:

答案 0 :(得分:0)

这应该有所帮助,根据需要调整列:

Connection Pool

P.S-可能是一个更好的想法,根本不使用表格,只需浮动每个&#34;单元格&#34; left(使用div元素),布局会响应