关于如何根据内部查询(循环查询)的结果解决查询问题,我遇到了一些问题。我已经尝试了所有我知道的方法,但它会中止while循环并中断。
它只是显示查询中的结果,它告诉我查询内的DOES有效,但它不会粘贴其信息,也不会粘贴其他元素(如信誉及其样式)。
$sql4 = mysqli_query($con, "SELECT * FROM as_sound_comments WHERE sound_id='$soundid'");
if(mysqli_num_rows($sql4) > 0){
while($row = mysqli_fetch_assoc($sql4)) {
echo "<div class='comment-content-full'>
<div class='comment-info'>
<table style='width: 98%'>
<td>
<table>
<td><p class='item-comment-info-name'><a class='blink' href='#'>";
$comment_poster_id = $row['poster_id'];
$sql5 = mysqli_query($con, "SELECT * FROM as_account WHERE id='$comment_poster_id'");
$innerrow = mysqli_fetch_assoc($sql5);
$comment_poster_username = $innerrow['username'];
$comment_poster_reputation = $innerrow['reputationlevel'];
echo $comment_poster_username;
"</a></p></td>
<td><div class='item-comment-info-reputation nlgreen'>8</div></td>
</table>
</td>
<td style='width: 20%'>
<p class='item-comment-info-posttime'><abbr class='timeago' title='< ". $row['added'] . "'></abbr></p>
</td>
</table>
</div>
<div class='comment-content-avatarandbox'>
<div class='comment-avatar'>
<img class='item-user-info-comment-avatar' src='images/test_avatar.jpg' alt='Avatar'>
<div class='arrow-left'> </div>
<div class='arrow-left-behind'> </div>
</div>
<div class='comment-box'>
<p class='comment-box-text'>" . $row['comments'] . "</p>
</div>
</div>
</div>";
}}else{ echo "sorry we didn't find no nothing";}
答案 0 :(得分:0)
根据评论回答关闭问题。无论何时在查询循环中进行查询,都可以使用JOIN
进行1次查询 -
$sql4 = mysqli_query($con, "SELECT * FROM as_sound_comments LEFT JOIN as_account ON as_account.id = as_sound_comments.poster_id WHERE as_sound_comments.sound_id='$soundid'");