Mouna Hachimi
Mouna Hachimi

Reputation: 1

Repeated in the table 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>

Upvotes: 0

Views: 935

Answers (1)

dev-null-dweller
dev-null-dweller

Reputation: 29462

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)

Upvotes: 2

Related Questions