符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
这篇文章将为大家详细讲解有关PHP+Mysql如何实现无刷新问答评论系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
创新互联建站是一家专业提供灵川企业网站建设,专注与成都网站设计、做网站、成都外贸网站建设公司、H5开发、小程序制作等业务。10年已为灵川众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。针对某一篇文章进行评论
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", "
", $_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'] . "]", "", $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(""); $.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 ;
关于“PHP+Mysql如何实现无刷新问答评论系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。