The implementation of PHP background comments

Source: Internet
Author: User
This article mainly introduces the PHP background comments on the implementation, has a certain reference value, now share to everyone, the need for friends can refer to

/** * Add Comments * Content comments * Addtime Comment time * UID Comment artwork */public Function Padd () {$param =input (' Para       M. ');       $param [' PID ']=session (' tid ');       if (Empty ($param [' uid '])) {return JSON ([' Code ' =>2, ' message ' = ' UID cannot be null ']); } $data =db (' comments ')->insertgetid ([' uid ' = + $param [' uid '], ' content ' = $param [' content '], ' addtime ' =>$       param[' Addtime '], ' pid ' = = $param [' pid ']];       if ($data) {return JSON ([' Code ' =>1, ' message ' = ' comment succeeded ']);       }else{return JSON ([' Code ' =>2, ' message ' = ' comment failed ']); }}/** * Comments Show * UID Comments Table * page pages * num number of bars */Public Function comment () {$param =input (       ' Param. ');       $param [' PID ']=session (' tid ');//user ID if (empty ($param [' page ')]) {$param [' page ']=1;       }if (Empty ($param [' num ')]) {$param [' num ']=5;       } if (Empty ($param [' uid '])) {return JSON ([' Code ' =>2, ' message ' = ' UID cannot be null ']); } $data =db (' comments ')->where (' uid ', $param [' uid '])->page ($param [' page '], $param [' num '])->select (); $commentslike =db ('       Commentslike ');       $people =db (' People '); foreach ($data as $k + $value) {//view the status of the comment like table $state = $commentslike->where ([' pid ' = ' + $param [' pid ')           ], ' uid ' = $param [' uid '], ' cid ' = $value [' data ']]->value (' state ');           if (empty ($state)) {$state = ' not yet liked '; } $data [$k] [' state ']= $state;//Get the comment person's mobile number $people = $people->where (' id ', $value [' pid '])->value (' Tel ')           ;           $data [$k] [' Tel ']= $people; Add the two-level comment to the array data if ($value [' rpid ']!== 0) {//$r _pid = $commentslike->where ([' id ' = = $value [' RP               ID ']])->value (' pid ');               $r _tel = $people->where (' id ', $value [' rpid '])->value (' tel ');           $data [$k] [' r_tel '] = $r _tel;           }else{$data [$k] [' r_tel '] = ';   }} return JSON ([' Code ' =>1, ' data ' = $data]); }/** * Comment Likes * UID Work ID */Public Function commentslike () {$param =input (' Param. ');        $param [' PID ']=session::get (' tid '), if (Empty ($param [' uid ')]) {return JSON ([' Code ' =>2, ' message ' = ' UID cannot be null '));      }//Judge whether the work has comments $comments =db (' comments ')->where (' uid ', $param [' uid '])->select (); if (!empty ($comments)) {//Judge if he has any likes $data =db (' Commentslike ')->where ([' uid ' = ' $param [' uid '], ' pid ' =&G           t; $param [' pid '], ' cid ' = $comments [' id ']])->find (); if (empty ($data)) {$like =db (' Commentslike ')->insertgetid ([' uid ' = + $param [' uid '], ' pid ' = = $param [' pid '],               ' CID ' = $comments [' id '], $param [' state ']=> ' likes ']);               if ($like) {return JSON ([' Code ' =>1, ' message ' + ' likes success ']);               }else{return JSON ([' Code ' =>1, ' message ' = ' praise failed ']); }}else{if ($data [' State ']== ' Cancel ' likes ') {$like =db (' Commentslike ')->where ([' UID ' =& Gt$param [' uid '], ' pid ' = $param [' pid '], ' CID ' + $comments [' id ']])->update ([$param [' State ']=> ' likes ']); }elseif ($data [' state ']== ' likes ') {$like =db (' Commentslike ')->where ([' uid ' = ' $param [' uid '], ' pid ' = = $pa               ram[' pid '], ' cid ' = $comments [' id ']])->update ([$param [' State ']=> ' cancel like ']);      }}}else{return JSON ([' Code ' =>2, ' message ' = ' This work has not been commented on ']); }}/** * Reply comment * UID work ID * Content Reply contents * CID This Comment ID * uid work ID PID comment Person ID */Public function       Reply () {$param [' pid '] = Session (' Tid ');       $param = input (' param. ');       The ID of the comment $param [' cid '] $data = db (' comments ')->where ([' id ' = = $param [' RID ']])->find ();       if ($data [' rid ']!== 0) {$param [' rid '] = $data [' Rid '];//the PID of the person being replied to. } $param [' rid '] = $data [' id '];//the PID of the person being replied to. $param [' rpid '] = $data [' pid '];//comments $param [' content ']//work ID $par am[' uid '] $param [' addtime '] = Date (' y-m-d h:i:s '); $id = db (' comments ')->insertgetid ([' uid ' = + $param [' uid '], ' content ' = $param [' content '], ' addtime ' =>$       param[' Addtime '], ' pid ' = = $param [' pid '], ' rid ' = = $param [' rid ']);       if ($id) {return JSON ([' Code ' =>1, ' messgae ' = ' recover success ']);       }else{return JSON ([' Code ' =>2, ' message ' = ' reply failed ']);  }}/** * View level Two comments * UID Artwork ID * RID this comment ID */Public Function getrcommtens ($value = ') {$data =   db (' comments ')->where ([' rid ' = = $param [' RID ']])->select (); }

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.