php 通过递归 查找父集分类/子集分类

—–获取父级分类—–

function get_parent_id($cid){
    global $db;
    $pids = '';

    $parent_id = $db -> getOne("select parent_id from eload_category where cat_id = '".$cid."'");
    if( $parent_id != '' ){
        $pids .= $parent_id;
        $npids = get_parent_id( $parent_id );
        if(isset($npids))
            $pids .= ','.$npids;
    }
    return $pids;
}

————获取子集分类————

function get_category( $category_id ){
    global $db;

    $category_ids = $category_id.",";
    $child_category = $db -> arrQuery("select cat_id from eload_category where parent_id = '$category_id'");
    foreach( $child_category as $key => $val )
        $category_ids .= get_category( $val["cat_id"] );
    return $category_ids;
}

你可能感兴趣的:(php 通过递归 查找父集分类/子集分类)