《PHP教程:php實現評論回復刪除功能》要點:
本文介紹了PHP教程:php實現評論回復刪除功能,希望對您有用。如果有疑問,可以聯系我們。
PHP學習簡單的評論回復刪除功能,具體內容如下
PHP學習一、數據庫
PHP學習建立兩張表,一是pinglun表;二是huifu表
PHP學習
PHP學習
PHP學習?效果如下:
PHP學習
PHP學習代碼如下:
PHP學習1.主頁面 main.php
PHP學習
<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>
";
}
}
?>
PHP學習?2.評論處理頁面 pinglunchuli.php
PHP學習
<?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");
PHP學習?3.回復處理頁面 huifuchuli.php
PHP學習
<!--?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");
PHP學習?4.刪除處理頁面 delchuli.php
PHP學習
<?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 "刪除失敗!";
}
PHP學習以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持維易PHP.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/757.html