我想以分层方式从 mysql 中删除记录。我有这样的数据库
id pid
1 0
2 1
3 2
我想删除以上所有记录。请在 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);
}
}
}
}
这是我的功能,我卡在这里它只删除一条记录