I want to delete record from mysql in hierarchical manner. i have my database like this
id pid
1 0
2 1
3 2
i want to delete all above record. please reply with proper function in php mysql.
function content_deleted($content_id=0, $parent_id=0)
    {
        if($parent_id==0)
        {
            $query = $this->db->query("SELECT content_id FROM tbl_content WHERE content_id = $content_id");
        }
        else
        {
            $query = $this->db->query("SELECT content_id FROM tbl_content WHERE content_parent_id = $content_id");  
        }
        if($query->num_rows()>0)
        {
            foreach($query->result() as $res)
            {
                $id = $res->content_id;
                if($parent_id==0)
                {
                    $this->db->query("DELETE FROM tbl_content WHERE content_id = $id"); 
                }
                else
                {
                    $this->db->query("DELETE FROM tbl_content WHERE content_parent_id = $id");
                    $this->content_deleted($content_id, $id);   
                }
            }   
        }
    } 
this is my function im stucked here it onnly delete one record
 
     
     
    