我想要做的就是對每條評論添加回復到我的評論系統,但我不知道該怎麼去做,有人可以向我展示或向我解釋如何添加此內容。添加回複評論系統
這是我的評論數據庫表。
id
user_id
target_id
comment
date_added
ip
type
這裏是我使用
public function addMovieComment($movieid, $comment, $user_id, $ip){
$comment = stripslashes(strip_tags($comment));
$comment = mysql_real_escape_string($comment);
$movieid = mysql_real_escape_string($movieid);
$user_id = mysql_real_escape_string($user_id);
$ip = stripslashes(strip_tags($ip));
$ip = mysql_real_escape_string($ip);
if (!($e = mysql_query("SELECT * FROM comments WHERE target_id='{$movieid}' AND user_id='{$user_id}' AND comment='{$comment}' AND type=2 AND ip='{$ip}'"))) {
exit(mysql_error());
}
if (mysql_num_rows($e) == 0) {
if (!($e = mysql_query("INSERT INTO comments(target_id,user_id,comment,date_added,type,ip) VALUES('{$movieid}','{$user_id}','{$comment}',NOW(),2,'{$ip}')"))) {
exit(mysql_error());
}
}
}
public function getMovieComments($movieid){
$movieid = mysql_real_escape_string($movieid);
if (!($e = mysql_query("SELECT comments.*,users.username, users.avatar FROM comments,users WHERE comments.user_id=users.id AND comments.type=2 AND comments.target_id={$movieid} ORDER BY comments.id DESC"))) {
exit(mysql_error());
}
$comments = array();
while (mysql_num_rows($e) && ($s = mysql_fetch_array($e))) {
extract($s);
$comments[$id] = array();
$comments[$id]['comment'] = stripslashes($comment);
$comments[$id]['user_id'] = $user_id;
$comments[$id]['username'] = $username;
$comments[$id]['date_added'] = $date_added;
$comments[$id]['avatar'] = $avatar;
}
return $comments;
}
功能這裏是我如何調用該函數添加並獲得意見。
if ((@$comment) && (@$addcomment) && (@$_SESSION['loggeduser_id'] && (@$ip))){
$comm->addMovieComment($mov['id'],$comment,$_SESSION['loggeduser_id'],$ip);
}
$comments = $comm->getMovieComments($mov['id']);
if (!count($comments)){ $comments = ''; $commentcount = 0; } else { $commentcount = count($comments); }
$smarty->assign("comments",$comments);
$smarty->assign("commentcount",$commentcount);
if ($commentcount==1){
$smarty->assign("comment_title",$commentcount." comment");
} else {
$smarty->assign("comment_title",$commentcount." comments");
}
我該怎麼去添加呢?
爲什麼不使用disqus或其他完善的評論系統而不是試圖開發自己的? – Charles
答覆只是碰巧有一個「父」的另一個評論。你的評論表中的「reply_to」字段並指向新的「評論」是回覆的記錄。 –
有時你喜歡做硬核的挑戰,也可以自己做呢? :-) – vogomatix