zoukankan      html  css  js  c++  java
  • php——两种无限级分类

    /**
    *   无级递归分类 TP框架
    *   @param   int     $assortPid   要查询分类的父级id
    *   @param   mixed   $tag         上下级分类之间的分隔符
    *   @return  string  $tree        返回的分类树型结构结果 
    *
    */
    function recursiveAssort($assortPid, $tag = '')
    {   
        $assort = M('goods_class')->where("class_pid = $assortPid")->field('class_id, class_name')->select();
        foreach ($assort as $value) {
            $tree .= '<option value="' . $value['class_id'] . '">' . $tag . $value['class_name'] . '</option>';
            $tree .= recursiveAssort($value['class_id'], $tag . '&emsp;');
        }
        return $tree;
    }
    复制代码
    /**
        *   利用php的引用传递 CI框架
        *
        */
        public function get_access()
        {
            $access = array();
            $field = 'id, pid, method, name, description';
            $q_access = $this->db->select($field)->get('access');
            $q_result = $q_access->result_array();
    
            if (!empty($q_result)) {
                $items = array();
                foreach ($q_result as $value) {
                    $items[$value['id']] = $value;
                }
                foreach ($items as $key => $item) {
                    if ($item['pid'] == 0) {
                        $access[] = &$items[$key];
                    } else {
                        $items[$item['pid']]['sub_access'][] = &$items[$key];
                    }
                }
            }
            return $access;
        }

    //自己写的无限级分类

    function tree(&$list,$pid=0,$level=0,$html='--'){
      static $tree = array();
      foreach($list as $v){
      if($v['pid'] == $pid){
      $v['sort'] = $level;
      $v['html'] = str_repeat($html,$level);
      $tree[] = $v;
      tree($list,$v['id'],$level+1);
       }
      }
      return $tree;
    }

    活着不应该靠泪水博取同情,而是需要靠汗水赢得掌声
  • 相关阅读:
    Java使用POI操作Excel合并单元格
    LinkedList查询分析
    Redis面试题及答案
    分布式架构基础:Java RMI详解
    什么是线程
    ehcache、memcache、redis三大缓存比较
    ehcache入门基础示例
    js 异步提交文件
    .net core Model对象转换为uri网址参数形式
    net core2.1 在过滤器中获取post的body参数
  • 原文地址:https://www.cnblogs.com/gaoxuqing/p/6703552.html
Copyright © 2011-2022 走看看