当前位置:网站首页>Three level classification display

Three level classification display

2022-06-11 13:27:00 Mr Fu f

 Insert picture description here Show the effect : Pictured
Code up It's using Yii frame

		/** isdelete  Deleted status  1: For display  pid = 0  It's level one  status = 1  It is opened for Zhejiang state  */
 		$sql = 'select * from {
    { The name of the classified table }} where eid = 1231 and isdelete = 1 and pid = 0 and status = 1 ';
        $res = Yii::app()->db->createCommand($sql)->queryAll();
        foreach ($res as $k => $v) {
    
            //  Define an empty array as the name of the secondary classification 
            $res[$k]['child'] = [];
            //  Query secondary categories . Condition as father id Equal to the classification of grades id
            $sql1 = 'select * from {
    { The name of the classified table }} where eid = 1231 and isdelete = 1 and pid = '.$v['id'].' and status = 1 ';
            $res1 = Yii::app()->db->createCommand($sql1)->queryAll();
            foreach ($res1 as $k1 => $v1) {
    
                //  Merge the query results into the defined array , Merge primary and secondary classifications 
                array_push($res[$k]['child'], $v1);

                //  Then define an array as the name of the three-level classification 
                $res[$k]['child'][$k1]['chlid2'] = [];

                //  Get the information of three-level classification 
                $sql2 = 'select * from {
    { The name of the classified table }} where eid = 1231 and isdelete = 1 and pid = '.$v1['id'].' and status = 1 ';
                $res2 = Yii::app()->db->createCommand($sql2)->queryAll();
                foreach ($res2 as $v2) {
    
                    //  Merge primary, secondary and tertiary classifications 
                    array_push($res[$k]['child'][$k1]['chlid2'], $v2);
                }
            }
        }
原网站

版权声明
本文为[Mr Fu f]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111320313756.html