您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php城市无限分类

2024/6/20 10:58:48发布20次查看
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_name 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;
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product