递归查留言

/**递归查留言
 * @param $data 原始数组
 * @param $ret
 * @return mixed
 */
function get_mess($data,&$ret){
    $comment=D("comment");//留言表
    foreach($data as $k => $v) {
        $ret[$v['id']] = $v;
        $p_con=$comment->where('pid='.$v['id'])->select();
        if($p_con) {
            get_mess($p_con, $ret);
        }
    }
    return $ret;
}
/**
 *递归获取评论列表
 */
function getCommlist($pid = 0,&$result = []){
    $arr = db('comment')->where('pid',$pid)->order("id")->select();
    if(empty($arr)){
        return array();
    }
    foreach ($arr as $cm) {
        $thisArr=&$result[];
        $cm["children"] = getCommlist($cm["id"],$thisArr);
        $thisArr = $cm;
    }
    return $result;
}

//删除留言,包含留言下所有留言

$id=I('id');
$comment=D('comment');
$pid=$comment->where('pid='.$id)->getfield('id',true);//下级回复id数组
$comment->where('id='.$id)->delete();
while ($pid) {
    $p=$pid;
    $pid=$comment->where(array('pid'=>array('in',$p)))->getfield('id',true);//重定义下级回复id数组
    $comment->where(array('id'=>array('in',$p)))->delete();
}
//获取所有下级评论id
function getCommentList($ids,$in=1){
    if(is_string($ids)){
        $ids=explode(',',$ids);
    }
    foreach($ids as &$id){
        $id=(int)$id;
    }
    $ids2=db('comment')->where('pid','in',$ids)->column('id');
    $arr=[];
    if($in){
        $arr=array_merge($arr,$ids);
    }
    $ids2=array_diff($ids2,$arr);
    while($ids2){
        $ids2=array_diff($ids2,$arr);
        $arr=array_merge($arr,$ids2);
        $ids2=db('comment')->where('pid','in',$ids2)->column('id');
    }
    return $arr;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值