我想在每条评论中添加一个回复按钮。
所以我在我的数据库中添加了一行**parent_id**
,
添加
评论表中的**input type="hidden" name="parent_id" id="parent_id" value="0"**
,
和本页中的js
**"var id = $(this).attr("id");$("#parent_id").attr("value", id);"**
回复
button add **a href="submit.php?$parent_id='.$id.'" class="reply">Reply
**,
现在我接下来要做什么来接收家长评论? 如果是我的剧本,请给我一个简短的指导。
我做错了什么/错过了吗?
index.php (重定向评论系统)
<?php
require('comments/inc_rate.php');
getComments("1");
submitComments("1",$_SERVER['PHP_SELF']);
?>
inc_rate.php
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<link rel="stylesheet" media="screen,projection" type="text/css" href="comments/css/comments.css" />
<script type='text/javascript' src='jquery-latest.pack.js'></script>
**<script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
});
});
</script>**
<?php
include("db.php");
function getComments($tutid){
//fetch all comments from database where the tutorial number is the one you are asking for
$results = mysql_query("SELECT * FROM comments WHERE qazi_id='$tutid' ORDER BY id DESC") or die(mysql_error());
//find the number of comments
$commentNum = mysql_num_rows($results);
echo' <div class="post-bottom-section">
<h2> '.$commentNum.' comments so far (<a href="#post" title="post your own">post your own</a>)</h2>
<div class="primary">
<ol class="commentlist">';
$count = mysql_numrows($results);
$i = 0;
while ($i < $count){
$id = mysql_result($results,$i,"id");
$qazi_id = mysql_result($results,$i,"qazi_id");
$name = mysql_result($results,$i,"name");
$email = mysql_result($results,$i,"email");
$description = mysql_result($results,$i,"description");
$url = mysql_result($results,$i,"url");
$date = mysql_result($results,$i,"date");
//heres our alternating hack
if($css != "depth-1"){ $css = "depth-1"; }else{ $css = "thread-alt depth-1"; }
echo' <li class="'.$css.'">
<div class="comment-info">
<img alt="" src="'.$grav_url.' class="avatar" height="42" width="42" />
<cite>
<a href="'.$url.'" title="'.$name.'">'.$name.'</a> Says: <br />
<span class="comment-data"><a href="'.$url.'" title="'.$date.'">'.$date.'</a></span>
</cite>
</div>
<div class="comment-text">
<p>'.BBCode($description).'</p>
</div>
</li>';
$i++;
echo '**<a href="submit.php?$parent_id='.$id.'" class="reply">Reply</a>**';
}
echo'</ol></div></div>';
}
?>
<?php
function submitComments($tutid2,$tuturl){
echo'
<a name="post">
<div class="post-bottom-section">
<h2>Leave a Reply</h2>
<div class="primary">
<form action="comments/submit.php" method="post" id="commentform">
<div>
<label for="name">Name <span>*</span></label>
<input id="name" name="name" value="" type="text" tabindex="1" />
</div>
<div>
<label for="email">Email Address <span>*</span></label>
<input id="email" name="email" value="" type="text" tabindex="2" />
</div>
<div>
<label for="website">Website</label>
<input id="website" name="website" value="" type="text" tabindex="3" />
</div>
<div>
<label for="message">Your Message <span>*</span></label>
<textarea id="message" name="message" rows="10" cols="18" tabindex="4"></textarea>
</div>
<div class="no-border">
**<input type="hidden" name="parent_id" id="parent_id" value="0"/>**
<input class="button" type="submit" name="post" value="Submit Comment" tabindex="5" title="Submit Comment" />
</div>
<input type="hidden" name="tuturl" value="'.$tuturl.'" />
<input type="hidden" name="tutid2" value="'.$tutid2.'" />
</form>
</div>
</div>';
}
?>
submit.php
<?
include("db.php");
if(isset($_REQUEST['post'])){
$tuturl = $_POST['tuturl'];
$qazi_id = $_POST['tutid2'];
$name = $_POST['name'];
$url = $_POST['website'];
$email = $_POST['email'];
$description = $_POST['message'];
$parent_id = $_POST['parent_id'];
$date = date("F j, Y; g:i a");
//Check form
if ($name == '' || $email == '' || $description == ''){
echo'Please fill in all fields before submitting the comment.';
exit();
}
//Submit data
$query = "INSERT INTO comments VALUES('','$qazi_id','$name','$email','$description','$url','$parent_id','$date')";
mysql_query($query);
echo "<h1>Submission Successful</h1>";
echo "Your comment has been submitted. You will now be redirected back to the last page you visited. Thanks!";
echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>";
} else {
echo "There was an error with the submission. ";
}
?>