如何使用javascript动态显示评论的多个回复?

时间:2016-11-08 03:55:32

标签: javascript php html

我想在一条评论下显示所有回复,但是,以下代码仅显示最后一条回复。我该怎么做才能让它显示所有回复而不仅仅是最后一个回复?

JAVASCRIPT

$(document).ready(function() {

"use strict"; 

function connect2mRev() { 

$.ajax({
    url:"reviews.php",
    type: "GET",
    dataType:"json",
    success:function(data)
    {    
        $.each(data, function() {

var html =
    '<div class="userR">' +

        '<div class="userDP_mP"><img src="display_pics/' + this.dp + '?' + new Date().getTime() + '" alt=""/></div>' +

        '<a href="#" data-ajax="false"><div class="userN">' + this.user '</div></a>' +

        '<img style="max-width:95%" class="reviewRI" src="ratP/' + this.avgrG + '.png" alt=""/>' +

        '<div class="review_m"><p>' + this.comment + '</p></div>' +


        '<div class="reply" id="reply">' +
            '<input type="button" data-theme="e" value="reply"/>' +
        '</div>' +

    '</div>'+

    '<div style="clear:both;width:80%;padding-left:15%; padding-top:2%;padding-bottom:15%">' +
        '<div class="userDP_reply"><img src="display_pics_citizens/' + this.dp_reply + '?' + new Date().getTime() + '" alt=""/></div>' +
            '<a href="#" data-ajax="false"><div class="userName_reply">' + this.user_reply + '</div></a>' +         
        '<div class="review_reply"><p>' + this.reply + '</p></div>' +
    '</div>';

$('div#Review').append(html).trigger('create');
});
},
});
}
});

HTML

<div id="Review"></div>

PHP

<?php

    $sql = "SELECT * FROM comments
            INNER JOIN user_details
            ON comments.userID=user_details.UserID 
            WHERE rat_n_comments.ID= '".$mID."'
            ORDER BY comments.Time DESC";

$result = $conn->query($sql);

$num_rows = mysqli_num_rows($result);

while ($row = $result->fetch_assoc()) {

$commentID = $row['ID'];

$getReplys = mysqli_query($conn, " SELECT * FROM replys_to_comments
                            INNER JOIN user_details
                            ON replys_to_comments.userID=user_details.UserID 
                            WHERE replys_to_comments.commentID= '".$commentID."'
                            ORDER BY replys_to_comments.Time DESC" );

            $slide = mysqli_fetch_array($getReplys);

            $reviews[]= array( 
                            'comment'=> $row['Comment'],
                            'commentID'=>$row['ID'],
                            'dp' => $row['display_pics'],
                            'user' => $row['Uname'],
                            'avgrG' => $ROW['prG'],
                            //*************** reply **************//
                            'reply' => $slide['Reply'],
                            'dp_reply' => $slide['display_pics'],
                            'user_reply' => $slide['Uname'],

                        );


        }

        header('Content-Type: application/json');
        echo json_encode ($reviews);

        }


        }

?>

提前感谢您的帮助。

0 个答案:

没有答案