如何在页面顶部/首页显示新评论?
之前我使用过代码,但是当我在评论框中添加回复系统时,它无法正常工作。
我用过的代码是:
$count = mysql_numrows($results);
$i = 0;
while ($i < $count){
$qazi_id = mysql_result($results,$i,"qazi_id");
$username = mysql_result($results,$i,"username");
$email = mysql_result($results,$i,"email");
$description = mysql_result($results,$i,"description");
$url = mysql_result($results,$i,"url");
$date = mysql_result($results,$i,"date");
other code
$i++;}
这是我目前的评论结构,上面的代码不能作为最后的评论首先再次显示总评论系统再次上面的代码:
$results = mysql_query("SELECT * FROM comments WHERE qazi_id='$tutid' ORDER BY id DESC") or die(mysql_error());
$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){
$qazi_id = mysql_result($results,$i,"qazi_id");
$username = mysql_result($results,$i,"username");
$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"; }
$q = "SELECT * FROM comments WHERE parent_id = 0";
$r = mysql_query($q);
while($row = mysql_fetch_assoc($r)) // Only main comment
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$username = $row['username'];
$email = $row['email'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo'
<div class="comment-info">
<img alt="" class="avatar" height="42" width="42" src="'.$grav_url.'"/>
<cite>
<a href="'.$url.'" title="'.$username.'">'.$username.'</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>
<a href="#post" class="reply" id="'.$id.'">Reply</a>
';
$query = "SELECT * FROM comments WHERE parent_id ='$id'";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res)) // Only main comment
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$username = $row['username'];
$email = $row['email'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo' <ul><li>
<div class="comment-info">
<img alt="" class="avatar" height="42" width="42" src="'.$grav_url.'"/>
<cite>
<a href="'.$url.'" title="'.$username.'">'.$username.'</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></ul>';
}}
$i++;
}echo'</ol></div></div>'; }
?>
答案 0 :(得分:0)
将您的查询更改为SELECT * FROM comments WHERE parent_id = 0 ORDER BY id DESC
。