如何使用ajax和php制作回复系统内部评论

如何使用ajax和php制作回复系统内部评论,php,jquery,ajax,Php,Jquery,Ajax,我有一个评论系统,它是在ajax的帮助下加载的,我想添加一个回复系统,它也是ajax加载的 jquery //其中,$myposted已经在文件中设置,该文件告诉我们评论发布在哪个帖子上,$msg是不同用户的唯一id $(“#提交建议“$mypostid.”)。单击(函数() { $.post(“comment.php”,{commentbutton:“commentbutton'.$mypostid.”,commentbody:$(“#postcomment'.$mypostid.”)val

我有一个评论系统,它是在ajax的帮助下加载的,我想添加一个回复系统,它也是ajax加载的 jquery


//其中,$myposted已经在文件中设置,该文件告诉我们评论发布在哪个帖子上,$msg是不同用户的唯一id
$(“#提交建议“$mypostid.”)。单击(函数()
{
$.post(“comment.php”,{commentbutton:“commentbutton'.$mypostid.”,commentbody:$(“#postcomment'.$mypostid.”)val(),commentid:“.$msg.”,
newcommentid:“'.$mypostid.'”},函数(数据)
{
$(“#显示'$myposted.''”).html(数据);
})
});
$(“文档”).ready(函数()
{
$.post(“comment.php”,{commentid:“.$msg.”,
newcommentid:“'.$mypostid.'”},函数(数据)
{
$(“#显示'$myposted.''”).html(数据);
})
});
comment.php

 <?php
        $postid=$_POST['newcommentid'];
        $addedby=$_POST['commentid'];
        $connection=mysqli_connect('localhost','root','123456789','register1');
    if(isset($_POST['commentbutton']))
    {
        if(isset($_POST['commentbody']) && !empty($_POST['commentbody']))
        {
            $commentbody=$_POST['commentbody'];
            $date=date("Y-m-d");
            $query=mysqli_query($connection,"insert into comments values('','$postid','$commentbody','$date','$addedby')");
        }
    }
    $selectquery=mysqli_query($connection,"select * from comments where postid='$postid' order by id DESC limit 2");
    while($selectbigrow=mysqli_fetch_array($selectquery))
    {
        $seecommentid=$selectbigrow['id'];
        $seecommentbody=$selectbigrow['commentbody'];
        $seeaddedby=$selectbigrow['addedby'];
        $registerquery=mysqli_query($connection,"select * from register where id='$addedby'");
        while($registerrow=mysqli_fetch_array($registerquery))
        {
            $registerprofilepic=$registerrow['profilepic'];
            $registerfirstname=$registerrow['firstname'];
            $registerlastname=$registerrow['lastname'];
            echo '<img src='.$registerprofilepic.' height="50" width="50"><a href="profile.php?id='.$seeaddedby.'" style="text-decoration:none">
            '.$registerfirstname.' '.$registerlastname.'</a><br>'.$seecommentbody.'<br>';
?>

 <?php
        $postid=$_POST['newcommentid'];
        $addedby=$_POST['commentid'];
        $connection=mysqli_connect('localhost','root','123456789','register1');
    if(isset($_POST['commentbutton']))
    {
        if(isset($_POST['commentbody']) && !empty($_POST['commentbody']))
        {
            $commentbody=$_POST['commentbody'];
            $date=date("Y-m-d");
            $query=mysqli_query($connection,"insert into comments values('','$postid','$commentbody','$date','$addedby')");
        }
    }
    $selectquery=mysqli_query($connection,"select * from comments where postid='$postid' order by id DESC limit 2");
    while($selectbigrow=mysqli_fetch_array($selectquery))
    {
        $seecommentid=$selectbigrow['id'];
        $seecommentbody=$selectbigrow['commentbody'];
        $seeaddedby=$selectbigrow['addedby'];
        $registerquery=mysqli_query($connection,"select * from register where id='$addedby'");
        while($registerrow=mysqli_fetch_array($registerquery))
        {
            $registerprofilepic=$registerrow['profilepic'];
            $registerfirstname=$registerrow['firstname'];
            $registerlastname=$registerrow['lastname'];
            echo '<img src='.$registerprofilepic.' height="50" width="50"><a href="profile.php?id='.$seeaddedby.'" style="text-decoration:none">
            '.$registerfirstname.' '.$registerlastname.'</a><br>'.$seecommentbody.'<br>';
?>