How to delete all categories and sub categories in PHP
ORdelete all categories and sub categories in OOP PHP
for php oop
public function deleteSub($aTable,$cat_id) {
$aSql = "SELECT * FROM {$aTable} WHERE parent_id = ".$cat_id;
$results = mysqli_query($this->databaseLink,$aSql);
while($child = mysqli_fetch_array($results))
{
$this->deleteSub($aTable,$child["id"]);
}
$request = "DELETE FROM {$aTable} WHERE id = ".$cat_id;
return mysqli_query($this->databaseLink,$request);
}
deleteSub(table_name, cat_id); ex -- deleteSub(cat, 10);
for php core
deleteSub(1);
function deleteSub($cat_id) {
$request = "SELECT * FROM ". TB_CATEGORY ." WHERE Parent = ".$cat_id;
$results = mysql_query($request);
while($child = mysql_fetch_array($results))
{
deleteSub($child["CID"]);
}
$request = "DELETE FROM ". TB_CATEGORY ." WHERE CID = ".$cat_id;
return mysql_query($request);
}
Related Posts--
* How to delete all categories and sub categories in PHP.
* How to delete main category and subcategories.
* How to delete main category with childs in PHP.
* PHP Function for delete main category with childs in PHP.
Comments
Post a Comment