PHP while语句中的while语句?

PHP while语句中的while语句?,php,mysql,Php,Mysql,分贝 代码示例到目前为止只列出了所有帖子,但只显示了一条评论? 到目前为止,我的代码只显示一条注释 请任何人帮助我,我真的需要帮助,我是一个在编码和尽我最大努力的noob。先谢谢你 <?php include("../db/db.php"); { /*if(isset($_POST["TimeLine"])){*/ $queryposts = "SELECT * FROM post"; $run_query = mysqli_query($con,$querypo

分贝 代码示例到目前为止只列出了所有帖子,但只显示了一条评论? 到目前为止,我的代码只显示一条注释

请任何人帮助我,我真的需要帮助,我是一个在编码和尽我最大努力的noob。先谢谢你

<?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

    }
}

您正在覆盖内部循环中的同一变量
$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

    }
}

您正在每个while循环中重置
$row
。对帖子和评论使用不同的行变量。在每个while循环中重置
$row
。对帖子和评论使用不同的行变量。仍然相同的结果$comments只显示一个结果,而不循环到单个帖子的下一个评论?显示数据库中的数据。你可以在你的问题中添加它的截图,或者添加到sqlfiddle的链接。你能告诉我你在哪里得到重复的评论吗?我刚刚检查了dropbox上的输出文件,如果对我来说没问题的话……只是截短了数据库进行再次测试,它似乎工作正常。很抱歉,两年前我编写的代码有点麻烦,但似乎记不起如何再出现内存丢失和注意力不集中的情况,所以现在对我来说有点困难。非常感谢d、 coder your Awesome仍然是相同的结果$comments只显示一个结果,不循环到下一个评论,只显示一篇文章?显示数据库中的数据。你可以在你的问题中添加它的截图,或者添加到sqlfiddle的链接。你能告诉我你在哪里得到重复的评论吗?我刚刚检查了dropbox上的输出文件,如果对我来说没问题的话……只是截短了数据库进行再次测试,它似乎工作正常。很抱歉,两年前我编写的代码有点麻烦,但似乎记不起如何再出现内存丢失和注意力不集中的情况,所以现在对我来说有点困难。非常感谢d、 你太棒了