How to find all IDs of children recursively?

后端 未结 6 596
死守一世寂寞
死守一世寂寞 2020-12-05 07:58

I would like to get all IDs from children in a tree with MySQL only.

I have a table like this:

ID parent_id name
1  0         cat1
2  1         subca         


        
6条回答
  •  [愿得一人]
    2020-12-05 08:43

    Seeing that the answer is basically no or at least not very easy with a single MYSQL statement, I'll post my php/mysql code to do the hierarchy list..

    function createCategorySubArray()
    {
        $categories = getSQL("SELECT pos_category_id FROM pos_categories");
        for($i=0;$i

    Then you call it by $cat_array = createCategorySubArray();

    I need this to find out which promotions based on product categories are being applied to the sub categories.

提交回复
热议问题