Php smarty foreach function **/

Source: Internet
Author: User
Tags foreach smarty template

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.

 

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.