这是我显示表格的代码:
<table id="ws_table" class="ws_table">
<thead>
<tr class="bg-light">
<th>WS Code</th>
<th>WS Name</th>
</tr>
</thead>
<tbody class="reportWs_table">
<?php
if (is_array($workschedules)) {
//$i=0;
foreach ($workschedules as $workschedulesingle) {
$cnt++;
?>
<tr>
<td class="">
<?php echo $workschedulesingle['workScheduleCode']; ?>
</td>
<td class="">
<?php echo $workschedulesingle['workScheduleName']; ?>
</td>
</tr>
<?php
}
} else {
}
?>
</tbody>
</table>
我的问题是桌子很长。所以我想一分为二。如何垂直拆分桌子?即,当条目超过20时,它将转到下一张表。如何创建它?
答案 0 :(得分:2)
•设置Index
$i=0
•循环每个row
•检查index
是否从0开始
•检查Index
是否达到20 /限制
•如果达到20 /极限,再次将Index
重置为0。
<?php
//INIT INDEX $i
$i = 0;
if(is_array($workschedules)){
// FOR EACH ROW
foreach($workschedules as $workschedulesingle){
//EVERY TIME THE INDEX START PRINT THE TABLE
if($i==0){
?>
<table id="ws_table" class="ws_table">
<thead>
<tr class="bg-light">
<th>WS Code</th>
<th>WS Name</th>
</tr>
</thead>
<tbody class="reportWs_table">
<?php } ?>
<tr>
<td class=""><?php echo $workschedulesingle['workScheduleCode'];?></td>
<td class=""><?php echo $workschedulesingle['workScheduleName'];?></td>
</tr>
<?php
//IF THE INDEX REACH 20/LIMIT, PRINT CLOSING TABLE TAGS
if($i==20){ ?>
</tbody>
</table>
<?php
}
//IF THE INDEX EXCEED 20/LIMIT, RESET $i TO 0 AND START AGAIN
$i++;
if($i>20){
$i=0;
}
}
}else{
}
?>