[英]Why is the same single result looping multiple times?
有多個博客條目,每個條目應顯示一次。 有一個“評論”鏈接,顯示和隱藏每個博客條目的評論。 我不知道為什么同樣的第一個結果不斷出現。 每次我添加新評論時都會發生這種情況(當前有5條評論,博客部分顯示5次,每個評論僅顯示第一個評論)。 根據用戶是否已登錄“評論”鏈接,顯示登錄鏈接還是(如果已登錄)表單字段以提交評論。
<?php
$conn = mysql_connect("...", "...", "...");
mysql_select_db("...");
$result = mysql_query("select * from blog");
$result2 = mysql_query("select * from blogcomment where blog.ID = blogcomment.blogID");
$i = 1;
while ($row = mysql_fetch_array($result))
{
echo "<h1>$row[title]</h1>";
echo "<p class ='second'>$row[blog_content]</p> ";
echo "<p class='meta'>Posted by .... • $row[date] • <a href='#' onclick=\"toggle_visibility('something$i'); return false\">Comments</a><div id='something$i' style='display: none;'><p class='third' >";
$i++;
while ($row = mysql_fetch_array($result2))
{
echo "$row[commentdate] • $row[username]</p><p>said:</p> <p>$row[comment]</p>";
if (isset ($_SESSION["gatekeeper"])) {
echo '<form method="post" action="postcomment.php"><input name="ID" type = "hidden" value = "' . $row[ID] . '" /><input name="comment" id="comment" type="text" style="margin-left:20px;"/><input type="submit" value="Add comment" /></form></div>';
}
else {
echo '<p class="third"><a href="register.html">Signup </a>to post a comment</p></div>';
}
}
}
mysql_close($conn);
?>
$i = 1;
while($row = mysql_fetch_array($result))
{
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.