PHP无限级分类碰到个问题,不知道错在哪儿?
<?phprequire_once('../chklogin.php');require_once("../byc_conn.php");?><?php//申明一个数组,...
<?php require_once('../chklogin.php'); require_once("../byc_conn.php");
?><?php //申明一个数组,统一存放查询分类列表数据$cateTree = array();//查询顶级分类$result= array();$result = getCategoryTree(0);//使用foreach查询顶级分类下的子分类foreach($result as $r){ $cateTree[] = $r; //查询子分类$result2 = getCategoryTree($r['id']);foreach($result2 as $r2){ $cateTree[] = $r2;//查询子分类$result3 = getCategoryTree($r2['id']);foreach($result3 as $r3){ $cateTree[] = $r3;//查询子分类$result4 = getCategoryTree($r3['id']);}}} //print_r($cateTree);/***将所有子级的分类全部查询出来****/function getCategoryTrees($id = 0,$cateTree = array()){ //顶级的分类 $result = getCategoryTree($id); //使用foreach查询顶级分类下的子分类foreach($result as $r){ //存放顶级分类 $cateTree[] = $r; $cateTree = getCategoryTrees($r['id'],$cateTree);}return $cateTree;}print_r(getCategoryTrees(0));/**//将查询子分类的操作,封装成函数*param int $id 子分类的父分类ID*@return array $result 子分类的列表**/function getCategoryTree($id = 0){$sql = "select * from dj_news_type where pid='($id)'";$result = array();$rs = mysql_query($sql);//$array=mysql_fetch_array($rs);while($row = mysql_fetch_assoc($rs)){$result[] = $row;}return $result;}?> 展开
?><?php //申明一个数组,统一存放查询分类列表数据$cateTree = array();//查询顶级分类$result= array();$result = getCategoryTree(0);//使用foreach查询顶级分类下的子分类foreach($result as $r){ $cateTree[] = $r; //查询子分类$result2 = getCategoryTree($r['id']);foreach($result2 as $r2){ $cateTree[] = $r2;//查询子分类$result3 = getCategoryTree($r2['id']);foreach($result3 as $r3){ $cateTree[] = $r3;//查询子分类$result4 = getCategoryTree($r3['id']);}}} //print_r($cateTree);/***将所有子级的分类全部查询出来****/function getCategoryTrees($id = 0,$cateTree = array()){ //顶级的分类 $result = getCategoryTree($id); //使用foreach查询顶级分类下的子分类foreach($result as $r){ //存放顶级分类 $cateTree[] = $r; $cateTree = getCategoryTrees($r['id'],$cateTree);}return $cateTree;}print_r(getCategoryTrees(0));/**//将查询子分类的操作,封装成函数*param int $id 子分类的父分类ID*@return array $result 子分类的列表**/function getCategoryTree($id = 0){$sql = "select * from dj_news_type where pid='($id)'";$result = array();$rs = mysql_query($sql);//$array=mysql_fetch_array($rs);while($row = mysql_fetch_assoc($rs)){$result[] = $row;}return $result;}?> 展开
1个回答
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询