如何在頁面頂部/首頁顯示新評論?如何在頁面頂部/首頁顯示新評論
我之前使用過一段代碼,但在我的評論框中添加回復系統時,s不起作用。
我使用的代碼是:
$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>'; }
?>
請[不要在新代碼中使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 *他們不再維護,並[已正式棄用](https://wiki.php.net/rfc/mysql_deprecation)*。看到[紅色框](http://uk.php.net/manual/en/function.mysql-connect.php)?學習[準備的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [這篇文章](http://php.net/manual/en/mysqlinfo.api.choosing.php)將幫助你決定哪些。 – 2014-09-23 17:29:17
謝謝,我現在看到了。 – jainul 2014-09-24 00:38:46
PDO在我的服務器中禁用。我之前嘗試啓用它,但失敗了。所以我很快就會在MySQLi上傳輸。謝謝你傑伊布蘭查德。 – jainul 2014-09-24 01:41:05