简单的评论回复删除功能,具体内容如下
一、数据库
建立两张表,一是pinglun表;二是huifu表
效果如下:
代码如下:
1.主页面 main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<meta http-equiv= "content-type" content= "text/html; charset=utf-8" > <title>无标题文档</title> <h1>朋友圈</h1> <div>内容:</div> <div>今天很嗨</div> <div><img src= "../picture/timg.jpg" width= "300" height= "200" ></div><br> <form action= "mainchuli.php" method= "post" > <input type= "text" hidden= "hidden" value= "zhangsan" name= "zhangsan" > <!--因为没有权限,这里给了一个默认值--> <textarea name= "content" ></textarea><input type= "submit" value= "评论" ><!--评论显示的地方--><!--单击评论提交内容进处理页面--> </form> <!--?php require "dbda.class.php" ; //调用封装类注意修改数据库名 $db = new dbda(); $sql = "select * from pinglun" ; $arr = $db --->query( $sql ,1); foreach ( $arr as $v ) { echo " <div style= "color:blue" >{ $v [1]} { $v [3]}</div> <div style= "color:blue" >{ $v [2]}</div> <form action= "delchuli.php?id={$v[0]}" method= "post" > //删除按钮 <input type= "submit" value= "删除" > </form> <form action= "huifuchuli.php?id={$v[0]}" method= "post" > //回复按钮 <textarea name= "comment" ></textarea><input type= "submit" value= "回复" > </form> "; $dc = new dbda(); $sql1 = "select * from huifu where jieshouid ={$v[0]}" ; //查询回复表中的id和传过去的id是不是一样的 $arr1 = $dc ->query( $sql1 ,1); foreach ( $arr1 as $k ) { echo "<div>{ $k [2]} { $k [3]}</div> <div>{ $k [4]}</div> "; } } ?> |
2.评论处理页面 pinglunchuli.php
1
2
3
4
5
6
7
8
9
10
|
<?php $zhangsan = $_post [ "zhangsan" ]; $content = $_post [ "content" ]; $time = date ( "y-m-d h:i:s" ); require "dbda.class.php" ; $db = new dbda(); $sql = "insert into pinglun values('','{$zhangsan}','{$content}','{$time}')" ; $db ->query( $sql ); header( "location:main.php" ); |
3.回复处理页面 huifuchuli.php
1
2
3
4
5
6
7
8
9
10
11
|
<!--?php $id = $_get [ "id" ]; //将点击回复的评论id传过来 $comment = $_post [ "comment" ]; //回复文本域中的内容 $me = "me" ; //这里是给定义了一个人 $times = date ( "y-m-d h:i:s" ); require "dbda.class.php" ; $db = new dbda(); $sql = "insert into huifu values('','{$id}', '{$me}','{$times}','{$comment}')" ; $db --->query( $sql ); header( "location:main.php" ); |
4.删除处理页面 delchuli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?php $id = $_get [ "id" ]; require "dbda.class.php" ; $db = new dbda(); $sql = "delete from pinglun where id='{$id}'" ; if ( $db ->query( $sql )) { header( "location:main.php" ); } else { echo "删除失败!" ; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。