Gets all subcategory ID numbers for the specified category
//gets all subcategory ID numbers for the specified categoryfunctionGetallchildcateids ($categoryID){ //Initializes an array of IDs $array[] =$categoryID; Do { $ids= ' '; $where[' pid '] =Array(' in ',$categoryID); $cate= M (' cate ')->where ($where),Select (); foreach($cate as $k=$v){ $array[] =$v[' ID ']; $ids. = ', '.$v[' ID ']; } $ids=substr($ids, 1,strlen($ids)); $categoryID=$ids; } while(!Empty($cate)); $ids=implode(‘,‘,$array); return $ids;//return string//return $array//return array}
Gets the specified category all parent ID numbers
//gets the specified category all parent ID numbersfunctionGetallfcateids ($categoryID){//Initializes an array of IDs$array[] =$categoryID; Do{ $ids= ' '; $where[' id '] =Array(' in ',$categoryID); $cate= M (' cate ')->where ($where),Select (); EchoM (' Cate ')_sql (); foreach($cate as $v){ $array[] =$v[' PID ']; $ids. = ', '.$v[' PID ']; } $ids=substr($ids, 1,strlen($ids)); $categoryID=$ids;} while(!Empty($cate));$ids=implode(‘,‘,$array); return $ids;//return string//return $array//return array}
Gets all the sub-classification keys for the specified category as IDs, with a value of category name
//gets all the sub-classification keys for the specified category as IDs, with a value of category namefunctionGETCATEKV ($categoryID){ //Initialize ID array, assign current classification $array[] = M (' cate ')->where ("id={$categoryID} ")->getfield (" Catename ")); Do { $ids= ' '; $where[' pid '] =Array(' in ',$categoryID); $cate= M (' cate ')->where ($where),Select (); EchoM (' Cate ')_sql (); foreach($cate as $k=$v) { $array[$v[' ID ']] =$v[' Catename ']; $ids. = ', '.$v[' ID ']; } $ids=substr($ids, 1,strlen($ids)); $categoryID=$ids; } while(!Empty($cate)); $ids=implode(‘,‘,$array); //return $ids;//Returns a string return $array //returns an array}
thinkphp Classification Query (get sub-categories of the current classification, get parent category, Next level category)