復制代碼 代碼如下:
$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;
}