php模仿qq空间或朋友圈发布动态、评论动态、回复评论、删除动态或评论的功能(中)
php  /  管理员 发布于 7年前   141
在上一篇随笔中已经将如何发布动态呈现了,那么现在来看一下剩下的评论动态、回复评论、删除动态和评论功能,这几个功能会有点绕~~~ 一、思路如下: (1)你发表动态之后,会有人评论这一条动态,当评论之后,你也会回复该评论;(此处评论要单独一张表,回复也要单独一张表) (2)删除动态:会将动态连同评论、回复全部删除;删除评论:只会删除该条评论 二、在写代码之前,我还是想把流程说一遍: (1)发表动态---评论---回复---再回复 (2)将上边的流程细化,我先在纸上写出,再上传,码字不能表达清楚(注意的是,我想要的功能的实现,并不是一模一样的哈) 三、还是先将代码分块解释,最后将主页面代码完全附上(含上一篇) 在上一篇中已经实现发布动态、弹出评论框,那么现在接着向下走: 分别看一下qqfriends,qqdongtai,qqpinglun,qqhuifu表,这是初始状态: 先以用户李四登录,由数据库qqfriends表中知道,李四的好友是zhangsan, 和zhaoliu,那么他的空间中显示的好友动态如下: 与上一篇相比,在这一篇中,谁登录的我用中文显示的: 第一步:评论 1、评论张三的动态,点击“确定”后,就是第二张图了~ 2、并将评论的内容写进数据库 pl-cl.php页面 查看qqpinglun表中是不是多了这一条 “为什么开心呢?”: 3、读取评论内容: 第二步:回复 1、回复刚刚的评论: 2、将回复内容写进数据库 hf-cl.php页面 查看qqhuifu表,是不是多了一行呢? 3、将回复内容读出: 回复内容已经显示了: 第三步:删除 1、删除动态:(含评论和回复) scdt-cl.php 2、删除评论:(含回复) scpl-cl.php 3、删除回复:(只自己) schf-cl.php 关于删除就不依次试了~~~注意包含关系就好了 主页面全部代码: 发表动态: 朋友动态: strquery($sql); echo "欢迎:"."{$name}"; ?>
//定义空字符串,容纳评论的id var code=""; $(".pl").click(function(){ code = $(this).attr("code"); //将评论的id重新赋值 }) //将评论写进数据库 $("#tjpl").click(function(){ var plnr = $(".pldt").val(); var plid = code; //取发动态的id $.ajax({ url:"pl-cl.php", data:{plnr:plnr,plid:plid}, type:"POST", dataType:"TEXT", success:function(data){ alert("评论成功!"); window.location.href="https:/article/main.php" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ; } }); })
query($sql,0);?>
//定义空字符串,容纳回复评论的id var ids=""; $(".hf").click(function(){ids = $(this).attr("ids"); //将评论的id重新赋值 // alert((ids)); $('#mM').modal('show'); }) //将回复评论写进数据库 $("#tjhf").click(function(){ var hfnr = $(".hfpl").val();// alert(hfnr);// alert(ids); $.ajax({ url:"hf-cl.php", data:{hfnr:hfnr,ids:ids}, type:"POST", dataType:"TEXT", success:function(data){ alert("回复成功!"); window.location.href="https:/article/main.php" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ; } }); })
query($sql,0);?>
query($sql,0);$sql2 = "delete from qqpinglun where dtid='{$code}'";$db->query($sql2,0);$sql3 = "delete from qqhuifu where cid=(select cid from qqpinglun where dtid='{$code}')";$db->query($sql3,0);header("location:main.php");?>
query($sql2,0);$sql3 = "delete from qqhuifu where cid='{$code}'";$db->query($sql3,0);header("location:main.php");?>
query($sql2,0);$sql3 = "delete from qqhuifu where cid='{$code}'";$db->query($sql3,0);header("location:main.php");?>