2012-01-08 27 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條件確保)