PHP + Mysql (source code) and mysql source code
The source code of a self-written comment system is shared with you, including emotices and comment mechanisms. The user name is random.
Comment on an article
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'); // Article id if (strlen (preg_replace ('/\ [[^ \)] +? \]/X', '', $ content) <10) {echo json_encode (array (" code "=>" short than 10 ", "error" => "the comment content cannot be less than 10 characters. "); Exit;} if (C (" DB_PWD ")! = '') {If (time ()-session (" comment_time ") <60 & session (" comment_time ")> 0) {// echo json_encode (array ("code" => "fast", "error" => "you submitted comments too quickly, please post a comment later. "); 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" => "repeated comments are detected. You seem to have submitted this comment"); 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 ". $ day_start. "AND ". $ day_end. "")-> count (); if ($ comment_num_day <= 5) {// if there are less than five entries per day, add points // addPoints ("comment", $ points_comment, $ data ['uid'], "comment obtained ". $ points_comment. "Points", 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 ));}}
Retrieve the corresponding comment list based on the paging Parameter
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(); }
Switch comment pages
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;'></div>"); $.get(getUrl("Box/comments"), { page: page, id: id, totalnum: totalnum, mtype: mtype }, function(data) { $("#comment_list").html(data) }) }) }
The comment table and emoticon table are already in the compressed package.
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 ;
Function implementation and demo address: www.erdangjiade.com/js/816.html