php smarty foreach 函数**/
<?php $tpl = new Smarty(); $tpl->template_dir = $cfg['path']['template']; $tpl->compile_dir = $cfg['path']['root'] . 'www.phprm.com'; $tpl->compile_check = $cfg['debug']; $tpl->debugging = false; $tpl->caching = 0; $tpl->cache_lifetime = 6000; $tpl->left_delimiter = '<!--{'; $tpl->right_delimiter = '}-->'; //配置smarty $Db = new Db(); try { $query = $Db->query($sql); if ($Db->rows($query)) { $array = $Db->fetch($query, 0); foreach ($array as $v => $_v) { $List[$v]['id'] = $_v[0]; $List[$v]['cntitle'] = $_v[2]; $List[$v]['i'] = $i++; } } } catch(Execption $e) { MessAge('调用参失败!'); } //php 处理与程序 tpl->assign('jsMenu_Deng', $List);
//下面为smarty模板处理foreach <!--{foreach from=$jsMenu_Deng item=item key=key}--> subcat[<!--{$item.i}-->] = new Array("<!--{$item.cntitle}-->","<!--{$item.upid}-->","<!--{$item.id}-->"); <!--{/foreach}--> var onecount=<!--{$item.i}-->;
//其实很简单就是把数据用php保存到数据,然后再由smarty foreach 来实现。
文章地址:http://www.phprm.com/frame/13d4eb6eb50581fb47b7b915cb5d60f0.html
转载随意^^请带上本文地址!