这是我关于这个主题的最后一个问题。我试图在我在网站上创建的帖子上发表评论。问题是,评论没有出现。
以下是代码:
<?php
$getid = $_GET['id'];
// Get relevent comments
$get_comments = mysql_query("SELECT * FROM post_comments WHERE post_id='$getid' ORDER BY id DESC");
$count = mysql_num_rows($get_comments);
if ($count != 0) {
while ($comment = mysql_fetch_assoc($get_comments)) {
$comment_body = $comment['post_body'];
$posted_to = $comment['posted_to'];
$posted_by = $comment['posted_by'];
$removed = $comment['post_removed'];
$comments = "<b><a href='$posted_by' target='_blank'>$posted_by</a> said: <br /></b>".$comment_body."<hr /><br />";
}
}
else
{
// Do nothing!
}
echo "
<br />
<div class='newsFeedPost'>
<div class='newsFeedPostOptions'>
<a href='javascript:;' onClick='javascript:toggle$id()'>Show Comments</a>
<div style='float: left;'>
<a href='$added_by'><img src='$profilepic_info' height='60' /></a>
</div>
<div class='posted_by'><a href='$added_by'>$added_by</a> wrote:</div>
<br /><br />
<div style='max-width: 600px; height: auto;'>
$body<br /><br /><br /><p />
</div>
Like – Re-Shout! – Comment
<br />$comments
</div>
</div>
";
}
}
?>
关于它为什么没有出现的任何想法?另外,不要介意MySQL代码,它仅用于测试目的!
我也听说过使用AJAX会是个不错的选择。我该怎么办? (我对PHP等很陌生。)
答案 0 :(得分:0)
试试吧。如果我理解你的代码,我会喜欢它。如果您需要更多信息,请提供完整的代码。
<?php
$getid = $_GET['id'];
// Get relevent comments
$get_comments = mysql_query("SELECT * FROM post_comments WHERE post_id='$getid' ORDER BY id DESC");
$count = mysql_num_rows($get_comments);
if ($count > 0) {
while ($comment = mysql_fetch_assoc($get_comments)) {
$comment_body = $comment['post_body'];
$posted_to = $comment['posted_to'];
$posted_by = $comment['posted_by'];
$removed = $comment['post_removed'];
}
}
else
{
// Do nothing!
}
echo '
<br />
<div class="newsFeedPost">
<div class="newsFeedPostOptions">
<a href="javascript:;" onClick="javascript:toggle'.$id.'()">Show Comments</a>
<div style="float: left;">
<a href="'.$added_by.'"><img src="'.$profilepic_info.'" height="60" /></a>
</div>
<div class="'.posted_by.'"><a href="'.$added_by.'">'.$added_by.'</a> wrote:</div>
<br /><br />
<div style="max-width: 600px; height: auto;">
'.$body.'<br /><br /><br /><p />
</div>
Like – Re-Shout! – Comment
<br /><b><a href='.$posted_by.' target='_blank'>'.$posted_by.'</a> said: <br /></b>'.$comment_body.'<hr /><br />
</div>
</div>
';
}
}
?>