How does the infinite pole classification get all the articles under a certain category?

< table > < thead > < tr > < th > Classification Table: < / th > < / tr > < / thead > < tbody > < tr > < td > id < / td > < td > department < / td > < td > pid < / td > < td > level < / td > < / tr > < tr > < td > 1 < / td > < td > Administration < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 2 < / td > < td > Marketing < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 3 < / td > < td > Finance < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 4 < / td > < td > Ministry of Foreign Trade < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 5 < / td > < td > General Administration < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 6 < / td > < td > bidding Department < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 7 < / td > < td > Engineering < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 8 < / td > < td > R & D Department < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 9 < / td > < td > sales < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 10 < / td > < td > domestic sales Department < / td > < td > 14 < / td > < td > 1 < / td > < / tr > < tr > < td > 11 < / td > < td > South China < / td > < td > 10 < / td > < td > 2 < / td > < / tr > < tr > < td > 12 < / td > < td > North China < / td > < td > 10 < / td > < td > 2 < / td > < / tr > < tr > < td > 13 < / td > < td > East China < / td > < td > 10 < / td > < td > 2 < / td > < / tr > < tr > < td > 14 < / td > < td > Guangzhou < / td > < td > 0 < / td > < td > 0 < / td > < / tr > < tr > < td > 15 < / td > < td > Guangdong < / td > < td > 0 < / td > < td > 0 < / td > < / tr > < tr > < td > 16 < / td > < td > template < / td > < td > 15 < / td > < td > 1 < / td > < / tr > < / tbody > < / table > < table > < thead > < tr > < th > Datasheet < / th > < / tr > < / thead > < tbody > < tr > < td > id < / td > < td > name < / td > < td > phone < / td > < td > weixin < / td > < td > qq < / td > < td > email < / td > < td > did (associated category ID) < / td > < / tr > < tr > < td > 1 < / td > < td > Zhang San < / td > < td > 10086 < / td > < td > test < / td > < td > 10000 < / td > < td > 10000@qq.com < / td > < td > 1 < / td > < / tr > < tr > < td > 2 < / td > < td > Li Si < / td > < td > 13800138000 < / td > < td > test1 < / td > < td > 123456 < / td > < td > 123456@qq.com < / td > < td > 2 < / td > < / tr > < tr > < td > 3 < / td > < td > Xiao Ming < / td > < td > 13888888888 < / td > < td > test23 < / td > < td > 987654 < / td > < td > 98654@qq.com < / td > < td > 11 < / td > < / tr > < / tbody > < / table > < hr >
$id = 14
public function selectRosterList($id)
    {
        $data = db("department")->where("pid",$id)->select();
        $rosters = [];
        foreach ($data as $key=>$value){
            $roster = db("roster")->where("did",$value["id"])->select();
            $rosters = array_merge($rosters, $roster);
            if ($value["pid"] != 0){
                $this->selectRosterList($value["id"]);
            }
        }
        return $rosters;
    }

Why can I only get the data of Zhang San and Li Si but not Xiaoming when I write like this?

May.15,2022

every time you execute, id is assigned a value of 14

clipboard.png


idea:
1. Recursive all subcategories of the specified classification first
2, id query based on subcategories

$rosters = []; each recursion, you will initialize
do not put the recursive department and the searcher together, recursion is only used to find all the sub-departments under this department, recursively come out a department array, and then query the personnel of the department ID in these arrays

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e32515-42ed5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e32515-42ed5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?