Php 如何循环或foreach它
我不能foreach循环我的评论和回复系统。我读了很多文章和例子,但不能将它们应用到我的案例中 这是我的评论系统和回复,这里的每一个想法都运作良好。但回复表单仅适用于最后/新评论。所以我需要循环每个评论。但是不行,请帮帮我Php 如何循环或foreach它,php,mysqli,Php,Mysqli,我不能foreach循环我的评论和回复系统。我读了很多文章和例子,但不能将它们应用到我的案例中 这是我的评论系统和回复,这里的每一个想法都运作良好。但回复表单仅适用于最后/新评论。所以我需要循环每个评论。但是不行,请帮帮我 global $dbh; $results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_er
global $dbh;
$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_error($dbh));
echo'<div class="comments"><div id="updates"><div class="content"><comment>';
// Show only main comment
while($row = mysqli_fetch_array($results))
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$username = $row['username'];
$description = $row['description'];
$parent_id = $row['parent_id'];
$date = $row['date'];
//echo comment
echo'<div class="comment">
<div class="cdomment_cheder">';
echo'<p><a href="#" title="">'.$username.'</a> Says:</p>';
echo'<span>'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
//reply
echo'<div class="reply_box"><a href="javascript: void(0)" class="reply" id="'.$id.'">Reply</a></div>';
//Reply form
echo'<div id="loader"></div><div class="reply_here" id="reply_here-'.$id.'" style="display:none;">
<form action="" method="post" id="repfrm" enctype="multipart/form-data">
<fieldset id="cmntfs">
<input type="hidden" name="username" tabindex="1" id="author" value="'.$username.'"/>
<textarea name="replycom" rows="2" tabindex="4" id="replycom" value=""></textarea>
<input type="hidden" name="parent_id" id="parent_id" value="0" />
<input type="hidden" name="tutid2" id="tutid" value="'.$tutid2.'" />
<button type="submit" name="submit" value="" tabindex="5" id="submit" class="repfrm">Post Reply</button>
</fieldset>
</form>
</div>';
// Show Reply of each comment
$query = "SELECT * FROM comments_reply WHERE parent_id ='".$id."'";
$res = mysqli_query($dbh,$query);
while($row = mysqli_fetch_array($res))
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$username = $row['username'];
$description = $row['description'];
$parent_id = $row['parent_id'];
$date = $row['date'];
//echo reply
echo' <div class="rcontent"><replycomment><ul>
<div class="comment">
<div class="cdomment_cheder">';
echo'<p class="name"><a href="#" title="">'.$username.'</a> Says:</p>';
echo'<span>'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
echo'</ul><replycomment></div>';
} //reply while close
} //comment while close
echo'</div><comment></div>';
不能从同一连接同时循环两个查询。您需要将第一个查询的所有结果带到PHP空间,然后对它们进行循环,然后执行第二个查询,或者使用无缓冲查询。好的,先生,我正在尝试。谢谢。我是新手,先生,你能帮我做吗。或者很少有指导方针来做这件事。谢谢。将第一次查询的所有结果提取到一个数组中,然后使用foreach循环该数组。其余的都一样。