示例代码:
<?php
echo "<table width=100% border=1 cellspacing=0 cellpadding=4>\n";
$curcol = 0; // 当前列
$percol = 7; // 每行7列
$fixcol = 0; // 修复单元格
for ($i=1; $i<=30; $i++) {
$curcol++;
if ($curcol % $percol == 1)echo "<tr>\n";
echo "<td>row$i</td>\n";
if ($curcol% $percol== 0) echo "</tr>\n";
}
if ($curcol % $percol != 0) {
for ($fixcol=1; $fixcol<=($percol- $curcol % $percol); $fixcol++) {
echo "<td> </td>\n";
}
}
if ($fixcol > 1) echo "</tr>\n";
echo "</table>\n";
?>
实现结果:
row1
row2
row3
row4
row5
row6
row7
row8
row9
row10
row11
row12
row13
row14
row15
row16
row17
row18
row19
row20
row21
row22
row23
row24
row25
row26
row27
row28
row29
row30