[原创]递归应用-遍历所有下层分类

 /*
 递归应用
 */
 function FindChild($parent) {
  $currList = "";
  $childList = "";
  $result = mysql_query("SELECT id FROM 表名 WHERE parent=" . $parent);
  while($rs = mysql_fetch_array($result))
  {
   $currList .= ($currList == "" ? "" : ",") . $rs["id"];
   //取得当前$rs["id"]的所有孩子id列表
   $tmpList = FindChild($rs["id"]);
   if($tmpList != "") {
    $childList .= ($childList == "" ? "" : ",") . $tmpList;
   }
  }
  
  return $currList . ($childList != "" ? "," : "") . $childList;
 }
阅读更多
文章标签: mysql function query
个人分类: PHP源码共享
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭