Record a bit of your own PHP code (1) Get any kind, unlimited level offline

Source: Internet
Author: User

//Get all DownlinefunctionGet_all_heeler ($user _id,$user _rank= 0){    $user _id_array=$user _id;  while(true) {        if(!Empty($user _rank)) {            $judge= "and User_rank =".$user _rank; }        //get all direct downline and accumulate inside the array        $row=$GLOBALS[' DB ']->getall ("Select User_name,user_id,user_rank from".$GLOBALS[' ECS ']->table (' users '). "WHERE parent_id in (".$user _id_array. ")" .$judge); if(!Empty($row)) {            $user _id_array=NULL; foreach($row  as $key=$value) {                                $user _id_array.=$value[' user_id ']. ","; //query There is no subordinate                $is _heeler.=$GLOBALS[' DB ']->getone ("Select user_id from".$GLOBALS[' ECS ']->table (' users '). "WHERE parent_id =".$value[' user_id '].$judge); }        }        //to judge if there are any subordinates, if any, continue the loop or exit the loop .        if(Empty($is _heeler)) {             Break; }        $is _heeler=NULL; //Cumulative Results        $result.=$user _id_array; //remove the comma at the end to prepare for the next query        if(substr($user _id_array,-1) = = ', ') {            $user _id_array=substr($user _id_array, 0,strlen($user _id_array)-1); }    }    //remove the comma at the end    $result.=substr($user _id_array, 0,strlen($user _id_array)-1); return $result;}

Record a bit of your own PHP code (1) Get any kind, unlimited level offline

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.