我有 2 张桌子、评论和八卦。
Gossips 有 3 列:id、userid、gossip。
Comments 有 4 列:id、userid、gossipid、comment。
我编写了这段代码,以便程序回显所有八卦和特定于每个八卦的评论。
$query = 'SELECT * FROM gossips ORDER BY id DESC LIMIT 0,10';
$result = mysqli_query($cxn, $query)
or die("Couldn't execute query");
while($row = mysqli_fetch_assoc($result))
{
echo '<div class="gossip">'.$row['gossip'].'</div><form action="comment.php" method="post"><input type="hidden" name="gossipid" value="'.$row['id'].'" />';
echo '<input type="text" name="comment" placeholder="Write your comment here"/><br /><input type="submit" value="Comment" /></form><br />';
$querycomment = "SELECT * FROM comment WHERE gossipid ='{$row['id']}' ORDER BY id DESC";
$resultcomment = mysqli_query($cxn, $query)
or die("Couldn't fetch comments.");
while($comments = mysqli_fetch_assoc($resultcomment))
{
echo $comments['comment'];
}
}
这段代码的输出只是回应八卦,并没有执行第二个 while 循环。可能是什么问题呢 ?