Php+mysql No refresh question and answer comments system detailed

Source: Internet
Author: User
Write a review of their own system source to share to everyone, including the expression, as well as the comment mechanism, the code is easy to understand, the need for a friend reference

Write a review of their own system source code to share to everyone, including emoticons, as well as comment mechanism. The user name is random

Comment on a post

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)) <) {echo Json_encode (array (" Code "= "Short than", "error" and "=" The content of the comment can not be less than 10 characters.       "));     Exit if (C ("db_pwd") = ") {if (time ()-session (" Comment_time ") < && session (" Comment_time ") > 0) {//2 minutes later release echo Json_encode (Array ("Code" = "Fast", "error" = "Your comment is too fast, please 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 ']. "]", "field ("id")->where ("content="). $data [' content '].     "'")->find ();       if ($info [' id ']) {echo json_encode ("Code" = "Comment_repeat", "error" and "=" detected a duplicate comment, 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 between". $day _start. "and". $day _end. "")->couNT (); if ($comment _num_day <= 5) {///less than 5 bars per day, add points//addpoints ("comment", $points _comment, $data [' uid '], "comment obtained". $p Oints_comment.       "Points", 5, 1);     }//AddMessage (' comment ', $data [' tid '], $data [' pid '], $data [' Mtype '], $data [' Touid '], $content);     } session ("Comment_time", Time ()); } }

Get a list of comments based on paging parameters

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 = ten * ($page-1);   $sql = "Tid =". $id. "and PID = 0";   $comments = M ("comment")->field ("Id,uid,content,addtime")->where ($sql)->order ("id DESC")->limit ($ Start. ",")->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) *);   $this->display (); }

Toggle Comment Paging

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 ("<p style= ' padding:20px 0;text-align:center; ') ></p> ");     $.get (GETURL ("box/comments"), {       page:page,       id:id,       totalnum:totalnum,       mtype:mtype     },     function (data) {       $ ("#comment_list"). HTML (Data)})}   )}

Comments and emoticons have been placed in the ZIP package.

CREATE TABLE IF not EXISTS ' sucai_comment ' (  ' id ' int (one) not null auto_increment,  ' uid ' int (one-by-one) not NULL,  ' to UID ' int ' (one) default ' 0 ',  ' pid_sub ' int (one) ' default ' 0 ',  ' tid ' int (one) not NULL,  ' pid ' int (one) ' default ' 0 ', 
   ' mtype ' tinyint (1) NOT NULL,  ' content ' text is not null,  ' addtime ' int (ten) not NULL,  PRIMARY KEY (' id ')) engin E=myisam DEFAULT Charset=utf8 auto_increment=5560;

The above is the whole content of this article, I hope that everyone's study has helped.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.