thinkphp Classification Query (get sub-categories of the current classification, get parent category, Next level category)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.