|
大家好。我写了个留言板,可以递归的删掉该信息下的所有子结点和它本身
测试过没问题了;请多指教;最近想找新的工作请各位能一起推荐。
源码共享:
PHP复制代码
function delete_message ()
{//delete the node and its all sub notes;
if($this->is_leaf_node())
{
$message_id=(int )$this->message_id();
$sql="delete from message where message_id=?";
$this->db->query($sql,array($message_id));
return;
}
else
{
//find its all sub node
$sql="select message_id from message
where parent_id=?";
$parent_id=(int )$this->message_id();
$res=$this->db->query($sql,array($parent_id));
foreach ($res->result_array() as $row)
{
$message=new Message_model ();
$message->set_message_id($row['message_id']);
//search and dell all the sub children nodes;
$message->delete_message();
//delete all sub nodes
$sql="delete from message where message_id=?";
$this->db->query($sql,array($row['message_id']));
}
//delete the self
$sql="delete from message where message_id=?";
$this->db->query($sql,array((int )$parent_id));
}
}
复制代码 |
|