解决办法之二:循环个行,列(并且带有一定的计算)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>手把手叫你如何循环Table-----之方法二:</title>
</head>
<body>
<table
border="0" cellpadding="2" cellspacing="1" bgcolor="#336699">
<?php
//假设你查询出来的数据结构是这样的:
$array_rs=array(0=>array("id"=>"1","photoName"=>"图片000","photoRoot"=>"img/0_0.gif"),
1=>array("id"=>"2","photoName"=>"图片111","photoRoot"=>"img/0_1.gif"),
2=>array("id"=>"3","photoName"=>"图片222","photoRoot"=>"img/0_2.gif"),
3=>array("id"=>"4","photoName"=>"图片333","photoRoot"=>"img/1_0.gif"),
4=>array("id"=>"5","photoName"=>"图片444","photoRoot"=>"img/1_1.gif"),
5=>array("id"=>"6","photoName"=>"图片555","photoRoot"=>"img/1_2.gif"),
6=>array("id"=>"7","photoName"=>"图片666","photoRoot"=>"img/2_0.gif"),
7=>array("id"=>"8","photoName"=>"图片777","photoRoot"=>"img/2_1.gif")
);
//先获得总行数
$row= count($array_rs) / 3 ;
//循环个行
for($r=0;$r<$row;$r++){
?>
<tr>
<?php
//循环列,固定3列
for($c=0;$c<3;$c++)
{
//确定行,列位置:
$index_row_cel= $r*3+$c ; //为什么乘以3呢,因为3列换嘛
//如果比总记录还多,直接退出
if($index_row_cel>=count($array_rs)) return ;
?>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><img name="" src="<?=$array_rs[$index_row_cel]["photoRoot"]?>"
border="0"
alt="<?=$array_rs[$index_row_cel]["photoName"]?>" /></td>
</tr>
<tr>
<td><?=$array_rs[$index_row_cel]["photoName"]?></td>
</tr>
</table>
</td>
<?php
} //----列循环结束
?>
</tr>
<?php
}// ----行循环结束
?>
</table>
</body>
</html>
[[it] 本帖最后由 ming206 于 2008-7-25 17:24 编辑 [/it]]