在表中重复Smarty + Php [英] Repeated in the table 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 smarty:
< td width =91>< table width =100height =100border =0cellpadding =1cellspacing =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>
< / a>
< / td>
{/ section}
< / tr>
首先,您要在每次迭代中重新分配tr,并在循环外部获取模板,所以它没有任何意义。获取所有结果后,您应该指定变量:
pre $ while($ row = mysql_fetch_array($ post_tv)){
$ show [] = $ row;
}
$ marsosmarty-> assign(show,$ show);
要移至表格中的下一行,可以使用节名称和模运算符:
< td width =91>< table width =100height =100border =0 cellpadding =1cellspacing =1bgcolor =#666666>
< tbody>< tr>
{section name = table loop = $ show}
< td bgcolor =#FFFFFF>
< a href =./ channel.php?id = {$ show [table] .id}target =az>
< / a>
< / td>
{if!$ smart.section.table.last&& $ smart.section.table.iteration%4 eq 0}
< / tr>< tr>
{/ if}
{/ section}
< / tr>
这样,在显示4个单元格后,会创建新的表格行(只有当单元格更多时,通过!$ smart.section.table.last
条件确保)
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>
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)
这篇关于在表中重复Smarty + Php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!