我在网站上有画廊,我需要删除所有文件夹
我的结构数据库:(g_folder)
id id_parent
1 0
2 0
3 2
4 2
5 3
例如
那么,我可以删除文件夹并删除所有父文件夹吗?
递归?
function delete(folder)
{
count = select id from g_folder where id_parent = folder
if(count == 0)
deleteFolderById(folder)
while(count != 0)
{
array = select id from g_folder where id_parent = folder
for i in range(count)
{
deleteFolderById(array[i])
}
count = select id from g_folder where id_parent = folder
delete(array[0])
}
}
我的算法错了,请帮忙!谢谢大家!