Home > Backend Development > PHP Tutorial > How to delete an infinite category and delete all subcategories under it at the same time_PHP Tutorial

How to delete an infinite category and delete all subcategories under it at the same time_PHP Tutorial

WBOY
Release: 2016-07-21 15:34:55
Original
1000 people have browsed it

Copy code The code is as follows:

$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 ('Deletion successful');
exit;
}
else
{
alert ('Deletion failed');
exit;
}
}

getChildrenIds This function has been given before. If you are not sure, please refer to Custom Function to Get the Subcategory ID Set under Unlimited Category IDs

Custom function to obtain the subcategory ID set under unlimited category IDs
Copy code The code is as follows:

/*—— —————————————————— */
//– Get the subcategory ID set under the infinite category 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;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322322.htmlTechArticleCopy the code as follows: $act = isset ($_GET['act']) ? trim ($_GET[ 'act']) : "; if ($act == 'del') { $sort_id = isset ($_GET['id']) ? intval($_GET['id']) : '0' ; $sort_ids = $sor...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template