/web/tmp/features.php
PHP | 45 lines | 35 code | 9 blank | 1 comment | 4 complexity | f165b331351de1fe3873fe7fff4ddd79 MD5 | raw file
- <?php
- mysql_connect("localhost","root","");
- $sql = mysql_select_db("yy");
- function nestify( $arrs, $depth_key = 'depth' ){
- $nested = array();
- $depths = array();
-
- foreach( $arrs as $key => $arr ) {
- if( $arr[$depth_key] == 0 ) {
- $nested[$key] = $arr;
- $depths[$arr[$depth_key] + 1] = $key;
- }else{
- $parent =& $nested;
- for( $i = 1; $i <= ( $arr[$depth_key] ); $i++ ) {
- $parent =& $parent[$depths[$i]];
- }
-
- $parent[$key] = $arr;
- $depths[$arr[$depth_key] + 1] = $key;
- }
- }
-
- return $nested;
- }
- $tree = array();
- //"SELECT b.id AS b__id, b.name AS b__name, b.published AS b__published, b.lft AS b__lft, b.rgt AS b__rgt, b.level AS b__level, p.id AS p__id, p.name AS p__name, p.name_tmp AS p__name_tmp, p.published AS p__published, p.feature_type AS p__feature_type, p.feature_type_tmp AS p__feature_type_tmp, p.deleted AS p__deleted, p.color AS p__color, p.lft AS p__lft, p.rgt AS p__rgt, p.level AS p__level FROM business_category b LEFT JOIN product_feature_to_category p2 ON (b.id = p2.category_id) LEFT JOIN product_feature p ON p.id = p2.product_feature_id LIMIT 100"
- $q = mysql_query("SELECT b.id AS b__id, b.name AS b__name, b.published AS b__published, b.lft AS b__lft, b.rgt AS b__rgt, b.level AS depth, p.id AS p__id, p.name AS p__name, p.name_tmp AS p__name_tmp, p.published AS p__published, p.feature_type AS p__feature_type, p.feature_type_tmp AS p__feature_type_tmp, p.deleted AS p__deleted, p.color AS p__color, p.lft AS p__lft, p.rgt AS p__rgt, p.level AS p__level FROM business_category b LEFT JOIN product_feature_to_category p2 ON (b.id = p2.category_id) LEFT JOIN product_feature p ON p.id = p2.product_feature_id LIMIT 100");
- while($row = mysql_fetch_assoc($q)){
- $tree[] = $row;
- }
- $tree = nestify($tree);
- function out($o){
- foreach($o as $t){
- echo str_repeat(" ",$t['depth']);
- echo $t['b__name']."<br>";
- if(!empty($t['child'])) out($t['child']);
- }
- }
- out($tree);