祝大家新年快乐!新年新气象!
看了别人的一个关于无限分类的文章,自己也写了一个!(开源)
2007-05-13 17:13:44 / 个人分类:php
演示页面:http://www.zlla.cn/demo/catalog_list.php
"[4HjbJ2Y0 至于添加删除之类的功能我就不多写了!仔细看看就知道这么用了.PHPChina 开源社区门户\Q1^'[Q8O
难的是显示方面PHPChina 开源社区门户:_j9UTU"H]&DM
希望高手扩展一下!
"[4HjbJ2Y0 至于添加删除之类的功能我就不多写了!仔细看看就知道这么用了.PHPChina 开源社区门户\Q1^'[Q8O
难的是显示方面PHPChina 开源社区门户:_j9UTU"H]&DM
希望高手扩展一下!
QUOTE:
这是类PHPChina 开源社区门户6FlI$oOs AKo
<?php
&[rrqp(_0 /*========================================================PHPChina 开源社区门户]aYNHS9A8[Z'i_
类名:catalogPHPChina 开源社区门户m7?b,g|6GOrk
功能:无限分级类
:~;B Q q9Ag0 方法:PHPChina 开源社区门户%[|-oqa ?6t
树形显示分类PHPChina 开源社区门户%vS(iZ|t @[ FB
catalog_show($id) //参数$id 递归调用
.sW;M M9Rn}0 流程:找到父分类为0所有根分类-> 一直递归取得所有分类并显示 PHPChina 开源社区门户P)w2XFc5@.e0D*q1?)f#?
添加分类
?-e1_k ?0yI{*@0 catalog_add($uid,$name) //$uid 父id //$name 分类名 PHPChina 开源社区门户"YoWXFK!F-^
流程:依据$uid,在此id下添加一个新子idPHPChina 开源社区门户3g)~2Y%gcj
删除分类
i.V.fzU3T0 catalog_del($uid)//参数 $uid 数要删除的分类
4DUMK4?0 修改分类
4i!F4al*j"Q w0 catalog_set($id,$name) //参数 $id 要修改的分类 //参数 $name 新的分类名
Ltdx/T \0 变量:PHPChina 开源社区门户$aKe4f6D*j1n-k
$config //数据库信息-> host,user,pass,dbname
&?X}$hd0 $catalog_dbname //分类数据库名PHPChina 开源社区门户b1[u7xZ8C{M
数据库:PHPChina 开源社区门户jo)V(iW
catalog_id //分类的自然序号PHPChina 开源社区门户)B;h)E%T|W
catalog_uid //分类的父分类
O0c+j n3Pm~/I0 catalog_name //分类名
|M`l'MYH0 catalog_path_number //亲缘树数字形式 0:1:2PHPChina 开源社区门户iDBJ;mj+n6h$eG
catalog_path_char //亲缘树字符形式 分类1:分类1.1:分类1.1.1
4Nt$r W.X;qIf,p0 参照文章 http://www.phpchina.com/12823/viewspace_4468.html
4s?*y6{/N)JG0 ========================================================*/PHPChina 开源社区门户4YU uh HfX%ZM
class catalog{PHPChina 开源社区门户MJ~!a3c7vkz2?.?
var $config;PHPChina 开源社区门户XX w`GN$Z*`
var $catalog_dbname;
8|dh@%J0 var $links;
:]xU/__7bsc0 private function connect(){PHPChina 开源社区门户u+P&Een4cN
$this->links = mysql_connect($this->config['host'],$this->config['user'],$this->config['pass']) or die("错误: 第".__LINE__."行<br>".mysql_error());
tg z+Y7[7`5{U+?"e0 mysql_select_db($this->config['dbname'],$this->links);
^_V~8uUC$e7[&y,H0 mysql_query("SET NAMES gb2312");PHPChina 开源社区门户/E hP ]eE#}'g
}
F6Z@L&Z&iIj0
3C8g%_z `4U0 function catalog_show($uid = 0){PHPChina 开源社区门户6p%R-j.t PT^[.tX5]
$this->connect();PHPChina 开源社区门户0yg1s1A%S
$sql = "SELECT * FROM ".$this->catalog_dbname. "
$],M r&af i0 WHERE catalog_uid = ". $uid ."
e[Wb3i Uy0 ORDER BY catalog_id ";PHPChina 开源社区门户.K/D%x7NJ%dg
$result = mysql_query($sql,$this->links) or die("错误: 第".__LINE__."行<br>".mysql_error());
GvGTJ2m H0\N0
Pn4UF)Hf0 if(mysql_num_rows($result) > 0){
H+TQcZ#S7L9V0 while ($row = mysql_fetch_assoc($result)){
$R.uP;]7V0 if($this->sun_catalog($row['catalog_id'])){//判断有没有子分类
&QI(^Mq1Fw$Q0 $cata_img = "<img id = 'img".$row['catalog_id']."' src='./img/last_node.jpg' ōnclick='click_catalog(".$row['catalog_id'].")'/>";
Ya$vd4zk0 }else{
,j&kB[)o-T8I0 $cata_img = "<img src='./img/sp.jpg'/>";
g1L5sfPj M0 }
Hf L8E2|-GYr[&G0 PHPChina 开源社区门户;J5`SMBR
$path = explode(":",$row['catalog_path_number']);
0XgQ)aF(L%Ad0 if(count($path) > 1){
