我写了一个函数来查询指定分类下的所有子分类ID问题,函数代码如下:
//获取子分类ID
function getChildrenId($pid=0){
global $conn;
$sortsql="select * from article_sort where enable=0 order by paixu asc,id asc";
$sortresult=$conn->query($sortsql);
while($sortrow = $sortresult->fetch_assoc()){
$sortarr[]=array($sortrow['id'],$sortrow['pid'],$sortrow['mingcheng']);
}
for($i=0;$i<count($sortarr);$i++)
{
if($sortarr[$i][1]==$pid)
{
$ChildrenId=$ChildrenId.",".$sortarr[$i][0];
getChildrenId($sortarr[$i][0]);
}
}
return $ChildrenId;
}
实际效果是只能查询出分类下的第一级子分类ID,第二级、第三级子分类ID就查询不出来了,我是php新手,高手帮看看是什么问题