Php implementation of the smarty template Infinitus classification method

Source: Internet
Author: User
Tags smarty template
This article mainly introduces how php implements the infinite pole classification of the smarty template, and analyzes in detail the related techniques of php using the smarty template to implement database query and infinite pole classification in combination with the instance form, for more information about how to use php to implement the Infinitus classification of smarty Templates, see the following example. We will share this with you for your reference. The details are as follows:

<? Php $ conn = mysql_connect ("localhost", "admin", "admin"); mysql_select_db ("lele_shop", $ conn ); mysql_query ("set names 'utf-8'"); $ class_arr = array (); $ SQL = "select * from ecs_brand ORDER BY brand_id asc "; $ query = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ query) {$ class_arr [] = array ($ row ['brand _ id'], $ row ['brand _ name'], $ row ['parent _ id'], $ row ['sort _ order']);} function dafenglei_select ($ m, $ id, $ index) {global $ class_arr; global $ str; $ n = str_repeat ("", $ m); // $ n = $ m; for ($ I = 0; $ I
 
  
". $ N. $ class_arr [$ I] [1]."\ N ";} else {$ str. ="
  ". $ N. $ class_arr [$ I] [1]."\ N ";} dafenglei_select ($ m + 1, $ class_arr [$ I] [0], $ index) ;}return $ str ;}$ aa = dafenglei_select, 0);?>
  Top-level category<? Php echo $ aa;?>
 

If smarty is used
Add one more

The code is as follows:

$ Smarty-> assign ('wuxian _ class', $ aa );


Add this sentence to the html page.

Top-level category{$ Wuxian_class}

Another problem is that $ str must be a global line; otherwise, an error occurs.

An extension of Infinitus classification:

We can write a function. every time we call this function, we only need to input this array and data to call it. Below is a method I have written.

function dafenglei_select(& $arr=array(),$m,$id,$index){    // global $class_arr;  global $str;   $n = str_repeat("    ",$m);  // $n = $m;  for($i=0;$i
 
  ".$n.$arr[$i][1]."\n";      }else{        $str.= "
  ".$n.$arr[$i][1]."\n";      }      dafenglei_select($arr,$m+1,$arr[$i][0],$index);    }  }   return $str;}
 

The call only needs to do this:

The code is as follows:

$ Aa = dafenglei_select ($ class_arr, 0, 0 );

I hope this article will help you design PHP programs based on the smarty template.

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.