解决办法之二:循环个行,列(并且带有一定的计算)
ttp://www.
手把手叫你如何循环Table-----之方法二://假设你查询出来的数据结构是这样的:
$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
?>
//循环列,固定3列
for($c=0;$c<3;$c++)
{
//确定行,列位置:
$index_row_cel= $r*3+$c ; //为什么乘以3呢,因为3列换嘛
//如果比总记录还多,直接退出
if($index_row_cel>=count($array_rs)) return ;
?>
" border="0" alt="=$array_rs[$index_row_cel]["photoName"]?>" /> |
=$array_rs[$index_row_cel]["photoName"]?> |
} //----列循环结束
?>
}// ----行循环结束
?>