Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/2/10 6:45:39 php+mysql实现无限级分类_[PHP教程]
表结构:id字段为分类标识,name字段为分类名,father_id字段为所属父分类的id,path字段为分类路径(储存该分类祖先的集合),isdir判断是否是目录(1为是,0为否)。
显示函数:
//count为分类等级 sort_list(str,fatherid,count) { rs = this->sql->re_datas("select * from sort where father_id = fatherid"); num = this->sql->sql_numrows(); i=0; n = 1; while(isset(rs[i])) { name = ""; for(n = 1 ; n < count ; n++) { name.="│ "; } if(i+1==num) { name.="└─".rs[i][name]; } else { name.="├─".rs[i][name]; } if(rs[i][isdir]) { str.="".name.""; } else { str.=name"; } temp = count+1; str = this->sort_list(str,rs[i][id],temp); i++; } return str; }
其中this->sql对象为sql操作类对象,re_datas()函数返回查到的数组,sql_numrows()函数返回查询到的数目 调用方法:sort_list = sort_list(sort_list,0,1);
以上为个人思想,还望大家多多指点。by 5w台灯
赞