Sample Code For Deleting Parent and Child N level
private function deleteChildren($parentId) {
$lochid = new Location();
$children = $lochid->where("parent_id", $parentId)->get();
if (!empty($children)) {
foreach ($children as $child) {
$this->deleteChildren($child->
$this->db->delete('countries_
}
}
}