/**
* 檢測該分類下所有子分類,並輸出ID(包括自己) * 數據庫字段 catid pid */ function getChildrenIds ($sort_id){ include_once APPPATH.'/libraries/db.php'; $db = new Db(); $ids = $sort_id; $sql = "SELECT catid,pid FROM jy_category WHERE pid =".$sort_id; $result = $db->select($sql); if ($result){ foreach ($result as $key=>$val){ $ids .= ','.$val['catid'].","; $ids .= getChildrenIds ($val['catid']); } } $idsArr = explode(",",$ids); $idsArr = array_unique($idsArr); $ids = implode(",",$idsArr); return $ids; }
/** * 檢測該分類下所有子分類,並輸出ID(不包括自己) * 數據庫字段 catid pid */ function getChildrenIds ($sort_id) { $db = $this->loadDB(); $ids = ''; $sql = "SELECT * FROM t_dept WHERE `parent_id` = '{$sort_id}'"; $query = $db->query($sql); $result = $query->result_array(); if ($result) { foreach ($result as $key=>$val) { $ids .= ','.$val['id']; $ids .= $this->getChildrenIds ($val['id']); } } return $ids; }