asp 无限级分类的删除方法

来源:百度知道 编辑:UC知道 时间:2024/06/02 19:12:13
我要的结果是,删除父目录后,下边他的所有子目录

数据库设计:
id 自增主键
pid 父目录的ID 是0则代表
pname 分类名字
ptype 是否是根目录,1是根目录,0不是

id pid pname ptype
1 0 根目录 1
2 1 一级目录 0
3 2 二级目录 0
4 3 三级目录 0

假设有以上数据 现在我要删除根目录,要求连同以下的子目录也一同删掉。

我现在的代码如下:

Pid=Request.QueryString("PID")

conn.execute("delete from mulu where id="&pid)
response.Write("<script>alert(""成功删除分类!"");location.href=""mulu.asp?ID="&ID&""";</script>")
set conn=nothing
response.End()

只能删除当前目录,无法删除子目录,请求帮忙。
qqlxinye的测试了,删除不了。
<%
id=Request.QueryString("id")
function del(id)
set rstemp=Server.CreateObject("ADODB.Recordset")
rstemp.open,"select * from Ssort where pid ="&id,conn,1,1
while not rstemp.eof
del(rstemp(id))
conn.execut

数据库设计不合理,你这样,不好实现无限级分类,更不方便管理
我给你推荐一种方法
ID pName pType
1 一级分类A 01
2 一级分类B 02
3 一级分类C 03
4 1级分类A下二级分类A 0101
5 1级分类A下二级分类B 0102
6 1级分类B下二级分类A 0201
7 1级分类B下二级分类A 0202
三级及三级以上的分类,通过pType来看,这样就好管理了
比如,你删除一级分类 A及所有子分类,可以这样
ID=Request.QueryString("ID")
pType=这儿通过读取数据库,得到相应ID的pType值
conn.execute("delete from mulu where Left(pType," & len(pType) & ")='" & pType & "'")
response.Write("<script>alert(""成功删除分类!"");location.href=""mulu.asp?ID="&ID&""";</script>")
set conn=nothing
response.End()

呵呵,用一个自己写的函数呀,这个函数递归先找,再在函数最下面删除

function del(id)
set rstemp=Server.CreateObject("ADODB.Recordset")
rstemp.open,"select * from mulu where pid ="&id,conn,1,1
while not rstemp.eof
del(rstemp("id"))
rstemp.movenext