Php 限制foreach循环中表中显示的列数
我有一个循环,它将数据输出到html表单和表中。如何限制它显示的列数,我之所以要这样做是因为我的空间有限,循环可能会运行1000次甚至更多,具体取决于用户 我想将列限制为6,因此如果循环运行6次,我希望它为另外6列创建一个新行,然后再次重复Php 限制foreach循环中表中显示的列数,php,html,css,forms,html-table,Php,Html,Css,Forms,Html Table,我有一个循环,它将数据输出到html表单和表中。如何限制它显示的列数,我之所以要这样做是因为我的空间有限,循环可能会运行1000次甚至更多,具体取决于用户 我想将列限制为6,因此如果循环运行6次,我希望它为另外6列创建一个新行,然后再次重复 <form method="POST" action="script.php"> <table><tr> <td><input type="checkbox" name="itemSelect[]" cl
<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>
这将有助于根据需要调整列:
<?php
$data = array_fill(0,100,"text");
$i = 0;
$columns = 8;
$rest = $columns-(count($data)%$columns);
?>
<table>
<tr>
<?php foreach($data as $cell): ?>
<?php if(!($i%$columns)) echo '</tr><tr>'?>
<td><?= $cell ?></td>
<?php $i++;?>
<?php endforeach;?>
<!-- fill rest cells-->
<?php if($rest<$columns):for($r=0;$r<$rest;$r++): ?>
<td>fill</td>
<?php endfor;endif; ?>
</tr>
</table>
填满
另外,最好不要使用表,只将每个“单元格”向左浮动(例如使用div元素),这样布局会有响应性您没有提供代码的重要部分(循环),我也无法完全理解您想要做什么。在我看来,您需要javascript,或者隐藏>6使用模。是否要在6列之后结束该行并添加新列?类似于if($iRowCount%6==0)echo“”代码>在循环内(带有行计数器)。