Php smarty foreach function **/
$ Tpl = new Smarty ();
$ Tpl-> template_dir = $ cfg ['path'] ['template'];
$ Tpl-> compile_dir = $ cfg ['path'] ['root']. 'Www .111cn.net/111cn /';
$ Tpl-> compile_check = $ cfg ['debug'];
$ Tpl-> debugging = false;
$ Tpl-> caching = 0;
$ Tpl-> cache_lifetime = 6000;
$ Tpl-> left_delimiter = '<! --{';
$ Tpl-> right_delimiter = '} --> ';
// Configure 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 ('Call parameter failed! ');
}
// Php processing and programs
Tpl-> assign ('jsmenu _ Deng', $ List );
// The following process foreach for The smarty Template
<! -- {Foreach from = $ jsMenu_Deng item = item key = key} -->
Subcat [<! -- {$ Item. I} -->] = new Array ("<! -- {$ Item. cntitle} --> "," <! -- {$ Item. upid} --> "," <! -- {$ Item. id} --> ");
<! -- {/Foreach} -->
Var onecount = <! -- {$ Item. I} -->;
// In fact, it is very easy to save the data in php and then implement it by smarty foreach.
?>