PHP implementation of Smarty template infinite Pole Classification method _php Example

Source: Internet
Author: User
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.

  • 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.