Php 如何从数据库中获取包含评论的新闻列表

Php 如何从数据库中获取包含评论的新闻列表,php,android,json,Php,Android,Json,我将为android制作新闻应用程序。我将json_编码到我的php文件中。但我只想在这段时间内添加评论。我到处找都找不到。你能帮帮我吗 这是我的php代码 if (!empty($result)) { // check for empty result if ($result->num_rows > 0) { $response["success"] = true; $response["news

我将为android制作新闻应用程序。我将json_编码到我的php文件中。但我只想在这段时间内添加评论。我到处找都找不到。你能帮帮我吗

这是我的php代码

if (!empty($result)) {

        // check for empty result
        if ($result->num_rows > 0) {

            $response["success"] = true;

            $response["news"] = array();
            while($row = $result->fetch_object()){
            $news = array();
            $news["id"] = $row->id;
            $news["title"] = $row->title;
            $news["details"] = $row->short;
            $news["thumbURL"] = $thumb.$row->images;
            $news["LargeImageURL"] = $big.$row->images;

            array_push($response["news"], $news);
            }

            // echoing JSON response
            echo json_encode($response);
        } else {
            // no news found
            $response["success"] = false;
            $response["message"] = "No news found";

            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no news found
        $response["success"] = false;
        $response["message"] = "No news found";

        // echo no users JSON
        echo json_encode($response);
    }
我想添加项目的评论,如在照片中


我发现它的工作很好。谢谢你的帮助

if (!empty($result)) {

        // check for empty result
        if ($result->num_rows > 0) {

            $response["success"] = true;

            $response["news"] = array();
            while($row = $result->fetch_object()){
            $commentsql = $db->query("SELECT * FROM comment where cid='".$row->id."' order by id desc limit 0,10");
            $comments = array();
            while($comm = $commentsql->fetch_object()){
            $comments[] = array(
                'id'    => $comm->id,
                'text'  => $comm->comment
                );
            }
            $news = array();
            $news["id"] = $row->id;
            $news["title"] = $row->title;
            $news["details"] = $row->short;
            $news["thumbURL"] = $thumb.$row->images;
            $news["LargeImageURL"] = $big.$row->images;
            $news["comment"] = $comments;

            array_push($response["news"], $news);
            }

            // echoing JSON response
            echo json_encode($response);
        } else {
            // no news found
            $response["success"] = false;
            $response["message"] = "No news found";

            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no news found
        $response["success"] = false;
        $response["message"] = "No news found";

        // echo no users JSON
        echo json_encode($response);
    }

你能在问题中包含你的代码而不是图像链接吗?在
while
-循环中做一个
while
-循环。这样你就可以为每一个项目获取每一条评论。我做不到。当我把while放进去的时候,它只在最后一个项目上显示。我不知道如何为每项创建数组。@IsmailAltunören如果在循环之前创建一个数组,并在每次迭代时将填充的数组推入空数组,则应该有一个包含数据的数组。我会尝试。但我不能发表评论。仅显示“注释”:“为空”。你能用工作版本编辑我的代码吗。问候@piddl0r