问个 smarty section 用法 {section name=aa loop=$array start=1 max=1} {$array[aa].id}{$array[aa].name}{/section} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的是二维数组。 实际上这样表示数组就可以了。$array = array(1=>'name1',2=>'name2',3=>'name3');用 foreach{foreach name=p item=item key=key from=$array}{if $smarty.p.iteration/2==0} id:$key name:$item{/if}{/foreach} {foreach name=p item=item key=key from=$array} {if $smarty.p.iteration/2==0} id:{$key} name:{$item} {/if} {/foreach} 贴出代码大家可能更明白我的意思{foreach item=category from=$categories}<tr> <td bgcolor="#COCOCO" colspan="2"><strong>{$category.categoryj} </strong></td></tr><tr> <td colspan="2"> <table width="100%" border="1" cellspacing="0" cellpading="5"> {section name=product loop=$products} {if $products[product].categoryid eq $category.categoryid} <tr height="70"> <td rowspan="2" width="15%"><a href="product.html">Thumbnail1</a></td> <td colspan="2" width="35%"> {$products[$smarty.section.product.index].productname}<br> {$products[product].description|nl2br} </td> {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} <td rowspan="2"><a href="product.html">Thumbnail2</a></td> <td colspan="2"> {$products[$smarty.section.product.index_next].productname}<br> {$products[$smarty.section.product.index_next].description|nl2br} </td> {else} <td rowspan="2"> </td> <td colspan="2"> </td> {/if} </tr> <tr> <td align="center">Price: {$products[product].price}</td> <td align="center" nowrap="nowrap"><a href="product.html">Buy</a></td> {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} <td><div align="center">Price: 4,000 </div></td> <td><div align="center"><a href="product.html">Buy</a></div></td> {else} <td><div align="center"> </div></td> <td><div align="center"> </div></td> {/if} </tr> {/if} {/section} </table> </td></tr>{/foreach}实际上我是想根据不同的分类,显示产品,每行两个。上面代码还有问题,这个$smarty.section.product.index_next用的不对 {foreach item=category from=$categories} <tr> <td bgcolor="#COCOCO" colspan="2"> <strong>{$category.categoryj} </strong> </td> </tr> <tr> <td colspan="2"> <table width="100%" border="1" cellspacing="0" cellpading="5"> {section name=product loop=$products} {if $products[product].categoryid eq $category.categoryid} <tr height="70"> <td rowspan="2" width="15%"> <a href="product.html">Thumbnail1 </a> </td> <td colspan="2" width="35%"> {$products[$smarty.section.product.index].productname} <br> {$products[product].description|nl2br} </td> {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} <td rowspan="2"> <a href="product.html">Thumbnail2 </a> </td> <td colspan="2"> {$products[$smarty.section.product.index_next].productname} <br> {$products[$smarty.section.product.index_next].description|nl2br} </td> {else} <td rowspan="2"> </td> <td colspan="2"> </td> {/if} </tr> <tr> <td align="center">Price: {$products[product].price} </td> <td align="center" nowrap="nowrap"> <a href="product.html">Buy </a> </td> {if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid} <td> <div align="center">Price: 4,000 </div> </td> <td> <div align="center"> <a href="product.html">Buy </a> </div> </td> {else} <td> <div align="center"> </div> </td> <td> <div align="center"> </div> </td> {/if} </tr> {/if} {/section} </table> </td> </tr> {/foreach} 变换了一种处理方式,将category和products存放到同一个数组中,通过section嵌套基本上解决问题。。谢谢大家的帮助 大致看了你的问题,index_next虽然会输出下一条数据,但并不能影响循环,所以你这种思路可能不行. 由于套接字没有连接并且没有提供地址,发送或接收数据的请求没有被接受。 数据库设计问题 这句代码错在哪里 PHP中的兼容问题 如何从数据库里面导出数据显示比如说[游戏][QQ游戏] 求一正则 求一个写法 关于文件上载的一段代码,赐教! php源文件给ioncube编码过,有办法破译吗? php一般是用什么工具啊 能不能看到我博客里面的视频? 如何将EXCEL批量导入MYSQL
实际上这样表示数组就可以了。
$array = array(1=>'name1',2=>'name2',3=>'name3');
用 foreach
{foreach name=p item=item key=key from=$array}
{if $smarty.p.iteration/2==0}
id:$key
name:$item
{/if}
{/foreach}
{if $smarty.p.iteration/2==0}
id:{$key}
name:{$item}
{/if}
{/foreach}
<tr>
<td bgcolor="#COCOCO" colspan="2"><strong>{$category.categoryj} </strong></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="1" cellspacing="0" cellpading="5">
{section name=product loop=$products}
{if $products[product].categoryid eq $category.categoryid}
<tr height="70">
<td rowspan="2" width="15%"><a href="product.html">Thumbnail1</a></td>
<td colspan="2" width="35%">
{$products[$smarty.section.product.index].productname}<br>
{$products[product].description|nl2br}
</td>
{if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
<td rowspan="2"><a href="product.html">Thumbnail2</a></td>
<td colspan="2">
{$products[$smarty.section.product.index_next].productname}<br>
{$products[$smarty.section.product.index_next].description|nl2br}
</td>
{else}
<td rowspan="2"> </td>
<td colspan="2"> </td>
{/if}
</tr>
<tr>
<td align="center">Price: {$products[product].price}</td>
<td align="center" nowrap="nowrap"><a href="product.html">Buy</a></td>
{if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
<td><div align="center">Price: 4,000 </div></td>
<td><div align="center"><a href="product.html">Buy</a></div></td>
{else}
<td><div align="center"> </div></td>
<td><div align="center"> </div></td>
{/if}
</tr>
{/if}
{/section}
</table>
</td>
</tr>
{/foreach}实际上我是想根据不同的分类,显示产品,每行两个。上面代码还有问题,这个$smarty.section.product.index_next用的不对
<tr>
<td bgcolor="#COCOCO" colspan="2"> <strong>{$category.categoryj} </strong> </td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="1" cellspacing="0" cellpading="5">
{section name=product loop=$products}
{if $products[product].categoryid eq $category.categoryid}
<tr height="70">
<td rowspan="2" width="15%"> <a href="product.html">Thumbnail1 </a> </td>
<td colspan="2" width="35%">
{$products[$smarty.section.product.index].productname} <br>
{$products[product].description|nl2br}
</td>
{if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
<td rowspan="2"> <a href="product.html">Thumbnail2 </a> </td>
<td colspan="2">
{$products[$smarty.section.product.index_next].productname} <br>
{$products[$smarty.section.product.index_next].description|nl2br}
</td>
{else}
<td rowspan="2"> </td>
<td colspan="2"> </td>
{/if}
</tr>
<tr>
<td align="center">Price: {$products[product].price} </td>
<td align="center" nowrap="nowrap"> <a href="product.html">Buy </a> </td>
{if $products[$smarty.section.product.index_next].categoryid eq $category.categoryid}
<td> <div align="center">Price: 4,000 </div> </td>
<td> <div align="center"> <a href="product.html">Buy </a> </div> </td>
{else}
<td> <div align="center"> </div> </td>
<td> <div align="center"> </div> </td>
{/if}
</tr>
{/if}
{/section}
</table>
</td>
</tr>
{/foreach}
index_next虽然会输出下一条数据,但并不能影响循环,所以你这种思路可能不行.