首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > PHP无限级分类查找父层函数
【标  题】:PHP无限级分类查找父层函数
【关键字】:PHP
【来  源】:http://blog.csdn.net/subnet/archive/2006/10/08/1326066.aspx

PHP无限级分类查找父层函数

 如:

classID          classFID          className          classCount
      1                  0                   中国                     0
      2                  1                   浙江                     0
      3                  1                   江苏                     0
      4                  2                   杭州                     0
      5                  4                  西湖区                   0

findFather('4','0') 显示 => 杭州

findFather('4','1') 显示 => 浙江

findFather('4','2') 显示 => 中国

findFather('4','3') 显示 => 中国 -> 浙江 -> 杭州

代码如下:

    // ========== findFather函数 START ==========
    // 功能:无限级分类之找出父层的相关数据
    // 参数:$classID,当前子层的编号
    //          $type,0找自己 1找父亲 2找祖先 3找家谱
    // 字段:classID主键,自生成 classFID父编号
    //          className分类名称 classCount分类统计

    function findFather($classID,$type)
    {
        
global $db,$flist,$forefather;
        
define("_STR_CUT", " -> ");

        
$db->query("set names 'utf8'");
        
$sql         = 'select * from tbl_test_search_class where classID = "'.$classID.'"';
        
$result         = $db->query($sql);
        
$recordCount = $result->num_rows;
        
if ($recordCount != 0)
        {
            
//取值
            $row       = $result->fetch_assoc();
            
$classFID  = $row['classFID'];
            
$classID   = $row['classID'];
            
$className = $row['className'];

            
//若找到祖先,即classFID为0,则将函数状态设为0
            if ($classFID == '0'$type='0';
        }
        
        
if ($type == '1'//找父亲
        {
            
$type = '0'//第二次开始函数状态为0,即循环2次
            findFather($classFID,$type);
        }
        
else if ($classFID != '0' AND $type == '2'//找祖先,状态type为2,祖先classFID不为0未找到
        {
            findFather(
$classFID,$type);
        }
        
else if ($type == '3')
        {
            findFather(
$classFID,$type);
            
$flist = $flist . _STR_CUT . $className//生成家谱
        }
        
else if ($type == '0')
        {
            
$forefather = $className;
        }

        
$result = $forefather . $flist;
        
return $result;
        
    }
    
// ========== findFather函数 END ==========
asp读sql server数据出现乱码问题解决方法:【上一篇】
同步和异步的区别:【下一篇】
【相关文章】
  • SOA和PHP
  • php学习笔记8-(定义函数)
  • php学习笔记9-(OOP)
  • rh9 下的apache1.3.37+mysql5.0.22+php4.4.4 配置
  • 优化安装 mysql+apache+php
  • php学习笔记6-(控制台程序)
  • php学习笔记7-(数组操作)
  • php学习笔记5—(文件操作)
  • php学习笔记1—(a+b)
  • php学习笔记2—(字符串和注释)
  • 【随机文章】
  • Dreamweaver构建Blog全程实录(8)-管理员页面的实现
  • 你的PC准备好迎接Longhorn了吗?
  • the first helloworld with j2me
  • DOS下的点阵汉字
  • 在数据窗口中实现动画
  • [SQL]中使用联接
  • 终于搞定intel的主板,ICH7相关
  • 一个BBS的源代码(五)
  • C#启动屏保
  • 系统总蓝屏,原来内存不干净
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.