您的位置:首页 > 编程语言 > PHP开发

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

2016-01-10 22:31 627 查看
—–获取父级分类—–

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: