PHP實現簡單的評論與回復功能還有刪除信息


我們首先先看一下功能

上面黑色的是評論的下面紅色的字體是回復的

再來看看怎么實現的

1.發布評論

<form action="pinglunchili.php" method="post">
<textarea name="content"></textarea>
<div><input type="submit" value="評論" /></div>

</form>

 這是評論的文本域

評論后的內容要存到數據庫去處理

因為這只是要實現簡單的評論與回復所以沒有設登錄權限所以里面的名字都是添加上去的

<?php

$yonghu="caocao";

$content=$_POST["content"];
$time =  date("Y-m-d H:i:s");


require "DBDA.class.php";
$db=new DBDA();
$sql="insert into pinglun values('','{$yonghu}','{$content}','{$time}')";

if($db->query($sql,0))
{
	header("location:pinglun.php");
}
else
{
	echo "你輸入錯誤!";
}

2.回復功能這里是評論一條后面跟着回復

<?php

require "DBDA.class.php";
$db=new DBDA();
$sql="select * from pinglun";
$arr=$db->query($sql);

foreach($arr as $v)
{
	
	echo "<div>{$v[0]}</div>
		  <div>{$v[1]}</div>
	          <div>{$v[2]}</div>
		  <div>{$v[3]}</div>
		  <form action='huifuchuli.php?id={$v[0]}' method='post'>
		  <input type='text' name='Comment' />
                  <input type='submit' value='回復' /></form>";
	$dc = new DBDA();	  
	$sql1="select * from huifu where jieshouid={$v[0]}";
	$arr1=$dc->query($sql1);
	foreach($arr1 as $f)
	{
		echo "<div style='color:red'>{$f[0]}</div>
			  <div style='color:red'>{$f[2]}</div>
			  <div style='color:red'>{$f[3]}</div>
			  <div style='color:red'>{$f[4]}</div>
			 ";
	}
}
?>

 將評論的內容與回復的內容遍歷出來顯示就是圖中的效果

這樣就可以實現一條評論后面跟着一條回復

3.再就是刪除信息

就是在回復的前面加一個刪除按鈕

 <form action='shanchuchuli.php?id={$v[0]}' method='post'>
			  <input type='submit' value='刪除' /></form>
		  <form action='huifuchuli.php?id={$v[0]}' method='post'>
		  <input type='text' name='Comment' />
          <input type='submit' value='回復' /></form>";

處理頁面

<?php
$id = $_GET["id"];

require "DBDA.class.php";
$db=new DBDA();
$sql="delete from pinglun where id='{$id}'";
if($db->query($sql,0))
{
	header("location:pinglun.php");
}
else
{
	echo "不能刪除!";
}
 

 這樣就出來圖中的刪除按鈕 

我們試試效果:

  

這樣就刪除信息了

加上登錄與權限的功能會在后面更新。

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM