我应该在帖子正文中显示评论编号。但是帖子正文在while中,如果我在while页面中放置评论num查询,那么就会很重!
我正在尝试做但不工作:
$comments_data = mysql_query("SELECT * FROM `comments` WHERE `blogid`='$bid' AND `postid`='$postid'") or die(mysql_error());
$coments_num = mysql_num_rows($comments_data);
if($post_query) {
while($post_data = mysql_fetch_array($post_query)) {
$postid = $post_data['id'];
$post_temp = $post;
$post_temp = str_replace('[post_comments]',$coments_num,$post_temp);
$posts .= $post_temp;
}
}
但如果我这样使用会起作用:(但有很多查询!)
if($post_query) {
while($post_data = mysql_fetch_array($post_query)) {
$postid = $post_data['id'];
$comments_data = mysql_query("SELECT * FROM `comments` WHERE `blogid`='$bid' AND `postid`='$postid'") or die(mysql_error());
$coments_num = mysql_num_rows($comments_data);
$post_temp = $post;
$post_temp = str_replace('[post_comments]',$coments_num,$post_temp);
$posts .= $post_temp;
}
}