In this paper, we describe the method of implementing Smarty template infinite Pole classification in PHP. Share to everyone for your reference, as follows:
<?php$conn = mysql_connect ("localhost", "admin", "admin"), mysql_select_db ("People_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); whil E ($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 (1,0,0);? >Top category <?php echo $aa;? >
If it's with smarty,
Add a Copy code code as follows: $smarty->assign (' Wuxian_class ', $AA);
Add this sentence to the HTML page.
Top-level classification {$wuxian _class}
Another issue to note is that $STR must be global, otherwise there will be an error.
Extension of infinite Pole classification:
We can write a function, each time we call this function we only need to pass in this array and data, we can call, here is a method I write.
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 just needs to do just that:
Copy the Code code as follows: $aa = Dafenglei_select ($class _arr,0,0,0);
It is hoped that this article will be helpful to everyone based on smarty template PHP program design.