This article mainly introduces the implementation of PHP background comments. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it.
/** * 添加评论 * content 评论内容 * addtime 评论时间 * uid 评论作品 */ public function padd(){ $param=input('param.'); $param['pid']=session('tid'); if(empty($param['uid'])){ return json(['code'=>2,'message'=>'uid不能为空']); } $data=db('comments')->insertGetId(['uid'=>$param['uid'],'content'=>$param['content'],'addtime'=>$param['addtime'],'pid'=>$param['pid']]); if($data){ return json(['code'=>1,'message'=>'评论成功']); }else{ return json(['code'=>2,'message'=>'评论失败']); } } /** * 评论展示 * uid comments表 * page 页数 * num 条数 */ public function comment(){ $param=input('param.'); $param['pid']=session('tid');//用户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不能为空']); } $data=db('comments')->where('uid',$param['uid'])->page($param['page'],$param['num'])->select(); $commentslike=db('commentslike'); $people=db('people'); foreach ($data as $k=>$value) { //查看评论点赞表的状态 $state=$commentslike->where(['pid'=>$param['pid'],'uid'=>$param['uid'],'cid'=>$value['data']])->value('state'); if(empty($state)){ $state = '还未点赞'; } $data[$k]['state']=$state; //获取评论人的手机号 $people=$people->where('id',$value['pid'])->value('tel'); $data[$k]['tel']=$people; //把二级评论添加到数组数据中 if($value['rpid'] !== 0){ // $r_pid = $commentslike->where(['id'=>$value['rpid']])->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]); } /** * 评论点赞 * uid 作品id */ public function commentslike(){ $param=input('param.'); $param['pid']=session::get('tid'); if(empty($param['uid'])){ return json(['code'=>2,'message'=>'uid不能为空']); } //判断该作品有没有评论 $comments=db('comments')->where('uid',$param['uid'])->select(); if(!empty($comments)){ //判断他有没有点赞 $data=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->find(); if(empty($data)){ $like=db('commentslike')->insertGetId(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id'],$param['state']=>'点赞']); if($like){ return json(['code'=>1,'message'=>'点赞成功']); }else{ return json(['code'=>1,'message'=>'点赞失败']); } }else{ if($data['state']=='取消点赞'){ $like=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->update([$param['state']=>'点赞']); }elseif($data['state']=='点赞'){ $like=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->update([$param['state']=>'取消点赞']); } } }else{ return json(['code'=>2,'message'=>'此作品还未评论']); } } /** * 回复评论 * uid 作品id * content 回复内容 * cid 这条评论的id * uid 作品id pid 评论人id */ public function reply(){ $param['pid'] = session('tid'); $param = input('param.'); //被评论的id $param['cid'] $data = db('comments')->where(['id'=>$param['rid']])->find(); if($data['rid'] !== 0){ $param['rid'] = $data['rid'];//被回复人的pid. } $param['rid'] = $data['id'];//被回复人的pid. $param['rpid'] = $data['pid']; //评论内容 $param['content'] //作品id $param['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'=>'回复成功']); }else{ return json(['code'=>2,'message'=>'回复失败']); } } /** * 查看二级评论 * uid 作品id * rid 这条评论的id */ public function GetRCommtens($value='') { $data = db('comments')->where(['rid'=>$param['rid']])->select(); }
The above is the entire content of this article. I hope it will be helpful to you. Everyone’s learning is helpful. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
PHP uses Azure Storage Blob to upload files
Introduction to PHP background image upload works
The above is the detailed content of Implementation of PHP background comments. For more information, please follow other related articles on the PHP Chinese website!

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
