[英]PHP while statement within a while statement?
Db db2代碼示例到目前為止只列出了所有帖子,但只顯示了一個評論? 到目前為止,我的代碼只顯示了一條評論?
請任何有幫助的人我真的需要幫助我在編碼和盡力而為的菜鳥。 先感謝您
<?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 >"
;
}
}
}
你在內循環中覆蓋了相同的變量$row
。 將其名稱更改為其他任何名稱。
$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.