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.