for($C=0; $C<2; $C++)
{
for($c=0; $c<4; $c++)
{
if($C==1 && $c==3) break;
$a[$C][$c] = ++$count;
}
}<table>
<{section loop=$array name=A}>
<tr>
<{section loop=$array[A] name=a}>
<td><{$array[A][a]}></td>
<{/section}>
</tr>
<{/section}>
</table>
结果:
1 2 3 4
5 6 7
{
for($c=0; $c<4; $c++)
{
if($C==1 && $c==3) break;
$a[$C][$c] = ++$count;
}
}<table>
<{section loop=$array name=A}>
<tr>
<{section loop=$array[A] name=a}>
<td><{$array[A][a]}></td>
<{/section}>
</tr>
<{/section}>
</table>
结果:
1 2 3 4
5 6 7
====================
..
..
$smarty->assign("t",array(1,2,3,4,5,6,7,8,9));
..
..1.tpl
===================================================
/*以下的数字4为列数*/
<table>
{section name=row loop=$t}
{if $smarty.section.row.start || $smarty.section.row.rownum%4==1}
<tr>
{/if}
<td>{$t[row]}</td>
{math equation="x - y" x=4 y=$smarty.section.row.rownum%4 assign=lackTd}
{if $smarty.section.row.last && $lackTd!=4}
{section name=tdloop loop=$lackTd}
<tr>
<td></td>
{/section}
{/if}
{if $smarty.section.row.last || $smarty.section.row.rownum%4==0}
</tr><tr>
{/if}
{/section}
</table>
<tr>
{<section name="td" loop=$row>}
{<if $smarty.section.td.index%4==0>}
</tr>
<tr>
{</if>}
图片:{<$gallery[tr][td].picname>}
{</section>}
</tr>
</table>-----------------------------------------------------------------------
建议:smarty的标志符别用{ },容易和css里的代码混淆.
=php====================================================
$sql = "SELECT ......";
$obj = $db->Execute($sql);
for($j=0;!$obj->EOF;$j++)
{
for($i=0;$i<4;$i++)
{
$arr[$j][$i]['id'] = $obj->fields['id'];
$obj->MoveNext();
}
}
$smarty->assign('arr',$arr);=tpl====================================================
<table width="100%">
<{section name="tr" loop=$arr}>
<tr>
<{section name="td" loop=$arr[tr]}>
<td width="25%">
<{if $arr[tr][td].id != null}>
<{$arr[tr][td].id}>
<{/if}>
</td>
<{/section}>
</tr>
<{/section}>
</table>
谢谢大家.