PHP+Mysql无刷新问答评论系统(源码)
网络编程 2021-07-05 08:23www.168986.cn编程入门
自己写的一个评论系统源码分享给大家,包括有表情,还有评论机制,代码简单易懂,需要的朋友参考下
自己写的一个评论系统源码分享给大家,包括有表情,还有评论机制。用户名是随机的
针对某一篇文章进行评论
function subment() { $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("ment_time") < 60 && session("ment_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("ment")->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("ment")->field("id")->where("content='" . $data['content'] . "'")->find(); if ($info['id']) { echo json_encode(array("code" => "ment_repeat", "error" => "检测到重复评论,您似乎提交过这条评论了")); exit; } $lastid = M("ment")->add($data); $points_ment = 20; if ($lastid > 0) { $day_start = strtotime(date("Y-m-d")); $day_end = $day_start + 3600 24; $ment_num_day = M("ment")->where("uid = " . $data['uid'] . " AND addtime between " . $day_start . " AND " . $day_end . "")->count(); if ($ment_num_day <= 5) { //少于5条每天,则添加积分 // addPoints("ment", $points_ment, $data['uid'], "评论获得" . $points_ment . "积分", 5, 1); } // addMessage('ment', $data['tid'], $data['pid'], $data['mtype'], $data['touid'], $content); } session("ment_time", time()); echo json_encode(array("code" => 200, "ment" => $content, "points" => $points_ment)); } }
根据分页参数获取对应评论列表
function ments() { $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"; $ments = M("ment")->field("id,uid,content,addtime")->where($sql)->order("id DESC")->limit($start . ",10")->select(); // echo M("ment")->getlastsql(); foreach ($ments as $k => $v) { $ments[$k]['sub'] = M("ment")->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("ments", $ments); $this->assign("ments_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"); $("#ment_list").html("<div style='padding:20px 0;text-align:center;'><img src='" + site_url + "Public/images/loading.gif'></div>"); $.get(getUrl("Box/ments"), { page: page, id: id, totalnum: totalnum, mtype: mtype }, function(data) { $("#ment_list").html(data) }) }) }
评论表和表情表已放在压缩包里
CREATE TABLE IF NOT EXISTS `sucai_ment` ( `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 ;
功能实现和demo原址
上一篇:PHP单例模式详解及实例代码
下一篇:PHP脚本自动识别验证码查询汽车违章
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程