2012-01-08 102 views
0

我在表表中重复的Smarty + PHP

的问题是重复我想,当它达到4行被转移到新的生产线

代码PHP表有问题:

// for : 
$tr = 1; 
while($row = mysql_fetch_array($post_tv)){ 
    $show[] = $row; 
    if ($tr == 4){ 
     $tr == 1; 
    } 
    $tr++; 
    $marsosmarty->assign("show",$show); 
    $marsosmarty->assign("tr",$tr); 
} 

代码的HTML智者:

<td width="91"><table width="100" height="100" border="0" cellpadding="1" cellspacing="1" bgcolor="#666666"> 
<tbody><tr> 
    {section name=table loop=$show} 
    {if $tr eq 3} </tr><tr> {/if} 
    <td bgcolor="#FFFFFF"> 
     <a href="./channel.php?id={$show[table].id}" target="az"> 
      <img src="{$show[table].a_IMG}" alt="{$show[table].a_DESC}" width="100" height="100" border="0" class="link-img" title="{$show[table].a_TITLE}"> 
     </a> 
    </td> 
    {/section} 
</tr> 
+0

问题是什么?你当前的代码发生了什么? – nicky77 2012-01-08 16:20:57

+0

问题在于结果显示在一行中我希望她在表格中显示(4行..) – 2012-01-08 16:27:57

+0

您是否可以尝试在整个循环中输出$ tr的值,以确保它确实满足您的$ tr eq 3条件 – nicky77 2012-01-08 16:34:13

回答

2

所有你在每一个伊特拉重新分配TR的第一并在while循环外部获取模板,所以它没有任何意义。

while($row = mysql_fetch_array($post_tv)){ 
    $show[] = $row; 
} 
$marsosmarty->assign("show", $show); 

移动到表格的下一行,您可以使用部分名称和模运算符这样的:你应该提取所有结果后分配变量

<td width="91"><table width="100" height="100" border="0" cellpadding="1" cellspacing="1" bgcolor="#666666"> 
<tbody><tr> 
    {section name=table loop=$show} 
    <td bgcolor="#FFFFFF"> 
     <a href="./channel.php?id={$show[table].id}" target="az"> 
      <img src="{$show[table].a_IMG}" alt="{$show[table].a_DESC}" width="100" height="100" border="0" class="link-img" title="{$show[table].a_TITLE}"> 
     </a> 
    </td> 
    {if !$smart.section.table.last && $smart.section.table.iteration % 4 eq 0} 
     </tr><tr> 
    {/if} 
    {/section} 
</tr> 

这种方式,显示4个单元格后新的表格行被创建(仅当存在更多单元格时,通过此!$smart.section.table.last条件确保)