How to delete category and subcategory with products by category id in PHP MYSQL
orPHP Function to delete all category subcategory and products by category id
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;
$request2 = "DELETE FROM product WHERE cat_id=".$cat_id;
mysqli_query($this->databaseLink,$request2);
return mysqli_query($this->databaseLink,$request);
}
Comments
Post a Comment