[英]PHP while statement within a while statement?
Db db2 Code Sample so far only lists all the posts but shows only one Comment ? Db db2代码示例到目前为止只列出了所有帖子,但只显示了一个评论? Code I have so far only shows one comment ? 到目前为止,我的代码只显示了一条评论?
Please anyone with assistance I really need help am a noob at coding and trying my best. 请任何有帮助的人我真的需要帮助我在编码和尽力而为的菜鸟。 Thank you in advance 先感谢您
<?php
include("../db/db.php");
{
/*if(isset($_POST["TimeLine"])){*/
$queryposts = "SELECT * FROM post";
$run_query = mysqli_query($con,$queryposts);
while($row = mysqli_fetch_array($run_query)){
$post_id = $row["post_id"];
$uid = $row["user_id"];
$content = $row["content"];
$like = $row["total_like"];
$date = $row["date_created"];
$uidpic = $row["profilepic"];
$email = $row["email"];
$pImage = $row["postimage"];
$pVideo = $row["video"];
echo "<b>POST: <b/><hr />".
$content."<hr >"
;
$querycomment = "SELECT * FROM comment WHERE comment_id = $post_id";
$run_queryb = mysqli_query($con,$querycomment);
while($row = mysqli_fetch_array($run_queryb)){
$ComId = $row["comment_id"];
$Comment = $row["comment"];
$ComDate = $row["comment_date"];
$ProfilePicpost = $row["profilepic"];
echo "<b>Comment: <b/><hr />".
$Comment."<hr >"
;
}
}
}
You are overwriting same variable $row
in inner loop. 你在内循环中覆盖了相同的变量$row
。 Change its name to anything else. 将其名称更改为其他任何名称。
$queryposts = "SELECT * FROM post";
$run_query = mysqli_query($con,$queryposts);
while($posts = mysqli_fetch_array($run_query)){
// Your post related code
$post_id = $posts["post_id"];
$uid = $posts["user_id"];
// Use $posts instead of $row
$querycomment = "SELECT * FROM comment WHERE comment_id = $post_id";
$run_queryb = mysqli_query($con,$querycomment);
while($comments = mysqli_fetch_array($run_queryb)){
// Your comment related code
$ComId = $comments["comment_id"];
$Comment = $comments["comment"];
// Use $comments instead of $row
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.