【发布时间】:2012-01-10 21:13:19
【问题描述】:
我有一条来自数据库的记录,其中包含 id 和 name,我希望它输出 在一个 colspan 上,其中所有记录都以 1-2-1-2-4 的方式分布。我给出http://imageshack.us/photo/my-images/42/wrongb.png/ 的程序清单如下:
<table border="1" cellspacing="0" cellpadding="0" width="200">
$itemCount = 0;
$itemIndex = 0;
$colSpan = 0;
$itemColCount = 0;
while ($itemCount < $total) { // $row = mysql_fetch_array($result)
$row = mysql_fetch_array($result)
<tr>
if ($itemIndex == 0 || $itemIndex == 2)
{
$colSpan=4;
$itemColCount = 1;
$itemIndex++;
}
else if ($itemIndex == 1 || $itemIndex == 3) {
$colSpan=2;
$itemColCount = 2;
$itemIndex++;
}
else {
$colSpan=0;
$itemColCount = 4;
$itemIndex = 0;
}
while ($itemColCount > 0)
{
if ($colSpan > 0)
{
print "<td colspan=\"$colSpan\">$itemCount".$row['name']."</td>"; // $row['itemName']
}
else
{
print "<td>item$itemCount".$row['name']."</td>"; // $row['itemName']
}
$itemCount++;
$itemColCount--;
}
$itemColCount = 0;
$colSpan = 0;
print "\n";
</tr>
}
</table>
我需要有关如何实现所需程序输出的帮助。我需要完成的是这个http://img828.imageshack.us/img828/4411/correctj.png。
【问题讨论】:
-
对不起,我看错图片和正确图片没有太大区别。你能这么好心解释一下你到底想达到什么目标吗?
标签: php mysql html record html-table