Home > php教程 > php手册 > 删除无限分类并同时删除它下面的所有子分类的方法

删除无限分类并同时删除它下面的所有子分类的方法

WBOY
Release: 2016-06-06 20:34:55
Original
1102 people have browsed it

今天晚上上Q的时候 ,一个以前的学员在网上问我,怎么删除一个无限分类的时候同时删除它下面的所有子分类。我把代码稍微整理了一下,发出来,放在php学员问答里

复制代码 代码如下:


$act = isset ($_GET['act']) ? trim ($_GET['act']) : ";
if ($act == 'del')
{
$sort_id = isset ($_GET['id']) ? intval($_GET['id']) : '0' ;
$sort_ids = $sort_id;
$childrenIds = getChildrenIds ($sort_id);
if (!empty ($childrenIds))
{
$sort_ids .= $childrenIds;
}
$sql = “delete from `article_sort` WHERE `sort_id` in ({$sort_ids})";
$res = mysql_query ($sql);
if ($res)
{
alert ('删除成功');
exit;
}
else
{
alert ('删除失败');
exit;
}
}


getChildrenIds 这个函数以前已经给出来过,网站空间,美国空间,不清楚的请参考 自定义函数之获取无限分类ID下的子类ID集

自定义函数之获取无限分类ID下的子类ID集

复制代码 代码如下:


/*—————————————————— */
//– 获取无限分类ID下面的子类ID集
//– $sort_id = $sort_id.getChildrenIds($sort_id);
//– $sql = " ….. where sort_id in ($sort_id)";
/*—————————————————— */
function getChildrenIds ($sort_id)
{
global $db;
$ids = ";
$sql = "SELECT * FROM ".$db->table('article_sort')." WHERE `parent_id` = '{$sort_id}'";
$res = $db->query ($sql);
if ($res)
{
while ($row = $db->fetch_assoc ($res))
{
$ids .= ','.$row['sort_id'];
$ids .= getChildrenIds ($row['sort_id']);
}
}
return $ids;
}

,香港服务器租用
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template