PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/web/tmp/features.php

https://bitbucket.org/mupenieks/dienasmediji
PHP | 45 lines | 35 code | 9 blank | 1 comment | 4 complexity | f165b331351de1fe3873fe7fff4ddd79 MD5 | raw file
  1. <?php
  2. mysql_connect("localhost","root","");
  3. $sql = mysql_select_db("yy");
  4. function nestify( $arrs, $depth_key = 'depth' ){
  5. $nested = array();
  6. $depths = array();
  7. foreach( $arrs as $key => $arr ) {
  8. if( $arr[$depth_key] == 0 ) {
  9. $nested[$key] = $arr;
  10. $depths[$arr[$depth_key] + 1] = $key;
  11. }else{
  12. $parent =& $nested;
  13. for( $i = 1; $i <= ( $arr[$depth_key] ); $i++ ) {
  14. $parent =& $parent[$depths[$i]];
  15. }
  16. $parent[$key] = $arr;
  17. $depths[$arr[$depth_key] + 1] = $key;
  18. }
  19. }
  20. return $nested;
  21. }
  22. $tree = array();
  23. //"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"
  24. $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");
  25. while($row = mysql_fetch_assoc($q)){
  26. $tree[] = $row;
  27. }
  28. $tree = nestify($tree);
  29. function out($o){
  30. foreach($o as $t){
  31. echo str_repeat("&nbsp;",$t['depth']);
  32. echo $t['b__name']."<br>";
  33. if(!empty($t['child'])) out($t['child']);
  34. }
  35. }
  36. out($tree);