最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

PHP+Mysql仿百度知道问答评论系统

来源:http://www.erdangjiade.com/ 沐浴春风 2016-12-23 14:06浏览(8022)

自己写的一个评论系统源码分享给大家,包括有表情,还有评论机制。用户名是随机的,添加积分和消息推送后面我们做演示DEMO

0、请不要问“在不在”之类的问题,有问题直接问!1、学生或暂时没有工作的童鞋,整站资源免费下载!2、¥9.9充值终身VIP会员,加我微信,826096331 拉你进VIP群学习!3、程序员加油,技术改变世界。在线 充值

PHP+Mysql仿百度知道问答评论系统
分类:PHP > Ajax 难易:初级
查看演示

加我微信,拉你进VIP群学习:

下载资源 下载积分: 100 积分

针对某一篇文章进行评论

function subcomment() {
    $data['uid'] = getUserid();
    $data['mtype'] = I("post.mtype", 0, 'int');
    if ($data['uid'] == '') {
        echo json_encode(array("code" => -1));
    } else {
        $content = addslashes(str_replace("\n", "<br />", $_POST['content']));
        $data['tid'] = I("post.id", 0, 'int'); //文章id
        if (strlen(preg_replace('/\[  [^\)]+?  \]/x', '', $content)) < 10) {
            echo json_encode(array("code" => "short than 10", "error" => "评论的内容不能少于10个字符。"));
            exit;
        }
        if (C("DB_PWD") != '') {
            if (time() - session("comment_time") < 60 && session("comment_time") > 0) {//2分钟以后发布
                echo json_encode(array("code" => "fast", "error" => "您提交评论的速度太快了,请稍后再发表评论。"));
                exit;
            }
        }



        $data['pid'] = I("post.pid", 0, 'int');
        $data['pid_sub'] = I("post.pid_sub", 0, 'int');
        $lyid = $data['pid_sub'] > 0 ? $data['pid_sub'] : $data['pid'];
        if ($lyid > 0) {
            $lyinfo = M("comment")->field("uid")->where("id='" . $lyid . "'")->find();
            $data['touid'] = $lyinfo['uid'];
        } else {
            $data['touid'] = 2;
        }

        $data['addtime'] = time();

        $emots = getTableFile("emot");

        foreach ($emots as $v) {
            $content = str_replace("[" . $v['name'] . "]", "<img alt='" . $v['name'] . "' src='" . __APP__ . "/Public/emot/" . ($v['id'] - 1) . ".gif'>", $content);
        }
        $data['content'] = addslashes($content);

        $info = M("comment")->field("id")->where("content='" . $data['content'] . "'")->find();
        if ($info['id']) {
            echo json_encode(array("code" => "comment_repeat", "error" => "检测到重复评论,您似乎提交过这条评论了"));
            exit;
        }

        $lastid = M("comment")->add($data);
        $points_comment = 20;

        if ($lastid > 0) {
            $day_start = strtotime(date("Y-m-d"));
            $day_end = $day_start + 3600 * 24;
            $comment_num_day = M("comment")->where("uid = " . $data['uid'] . " AND addtime between " . $day_start . " AND " . $day_end . "")->count();
            if ($comment_num_day <= 5) { //少于5条每天,则添加积分
//                    addPoints("comment", $points_comment, $data['uid'], "评论获得" . $points_comment . "积分", 5, 1);
            }
//                addMessage('comment', $data['tid'], $data['pid'], $data['mtype'], $data['touid'], $content);
        }
        session("comment_time", time());

        echo json_encode(array("code" => 200, "comment" => $content, "points" => $points_comment));
    }
}

根据分页参数获取对应评论列表

function comments() {
    $id = I("get.id", 0, 'int');
    $mtype = I("get.mtype", 1, 'int');
    $page = I("get.page", 1, "int");
    $totalnum = I("get.totalnum", 1, "int");
    $start = 10 * ($page - 1);
    $sql = "tid = " . $id . " AND pid = 0";
    $comments = M("comment")->field("id,uid,content,addtime")->where($sql)->order("id DESC")->limit($start . ",10")->select();
//        echo M("comment")->getlastsql();
    foreach ($comments as $k => $v) {
        $comments[$k]['sub'] = M("comment")->field("id,uid,content,pid_sub")->where("tid = " . $id . " AND pid = " . $v['id'] . "")->order("id ASC")->select();
    }
    $this->assign("id", $id);
    $this->assign("mtype", $mtype);
    $this->assign("comments", $comments);
    $this->assign("comments_num", $totalnum - ($page - 1) * 10);
    $this->display();
}

切换评论分页

if ($("#detail-page").length > 0) {
    var id = $("#detail-page").attr("data-id");
    var mtype = $("#detail-page").attr("data-mtype");
    var totalnum = $("#detail-page").attr("data-totalnum");
    $("#detail-page").children("a").click(function() {
        var page = parseInt($(this).attr("data-page"));
        $("#detail-page").children("a").removeClass("current");
        $("#detail-page").children("a").eq(page - 1).addClass("current");
        $("#comment_list").html("<div style='padding:20px 0;text-align:center;'><img src='" + site_url + "Public/images/loading.gif'></div>");
        $.get(getUrl("Box/comments"), {
            page: page,
            id: id,
            totalnum: totalnum,
            mtype: mtype
        },
        function(data) {
            $("#comment_list").html(data)
        })
    })
}

评论表和表情表已放在压缩包里

CREATE TABLE IF NOT EXISTS `sucai_comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `touid` int(11) DEFAULT '0',
  `pid_sub` int(11) DEFAULT '0',
  `tid` int(11) NOT NULL,
  `pid` int(11) DEFAULT '0',
  `mtype` tinyint(1) NOT NULL,
  `content` text NOT NULL,
  `addtime` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5560 ;
声明:本文为原创文章,如需转载,请注明来源erdangjiade.com并保留原文链接:https://www.erdangjiade.com/js/816.html
评论100
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

  • 头像 99楼
    05-15 09:17
    lyw254515
    sks1wwwwwww
  • 头像 98楼
    05-15 09:14
    lyw254515
    生生世世搜索到的
  • 头像 97楼
    12-17 09:29
    wwwww_xiaobai
    积分来喽
  • 头像 96楼
    10-06 21:35
    康露依
    测试一下
  • 头像 95楼
    04-06 11:10
    xhl111
    nihao<br />
  • 头像 94楼
    07-17 06:28
    三小啊啊啊啊
    這個用不了了<br />
  • 头像 93楼
    05-21 18:14
    caihong
    這個用不了!
    1
    caihong

    不知道爲什麽我用不了

  • 头像 92楼
    05-20 21:40
    cchong
    這個好用嗎?????????????
  • 头像 91楼
    05-10 13:52
    baitongda
    黄雪辰阿斯蒂芬
  • 头像 90楼
    01-28 11:01
    huykhang
    link dowload
1 2