doucaishou0074 2012-01-08 16:11
浏览 36

在Smarty + Php表中重复

I have a problem in in the table

The problem is to repeat I want when it reaches 4 rows to the table is transferred to the new line

Code 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);
} 

Code Html smarty :

<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>
  • 写回答

1条回答 默认 最新

  • dtz55359 2012-01-08 20:47
    关注

    First of all you are reassigning tr in every iteration, and fetching template it outside while loop, so it makes no sense. You should assign variable after fetching all results:

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

    To move to the next row in table, you can use section name and modulo operator like this:

    <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>
    

    This way, after displaying 4 cells new table row is created (only if there are more cells, thats ensured by this !$smart.section.table.last condition)

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程