如何使用ajax和php在评论中进行回复系统

时间:2016-03-16 11:30:28

标签: php jquery ajax

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

<script src="jquery.js"></script>
 <script>
    //where $mypostid is already set in the file which tells us on which post the comment is posted and $msg is unique id for diffrent user
        $("#submitcomment'.$mypostid.'").click(function()
        {
            $.post("comment.php",{commentbutton: "commentbutton'.$mypostid.'",commentbody:$("#postcomment'.$mypostid.'").val(),commentid: "'.$msg.'",
            newcommentid: "'.$mypostid.'"},function(data)
                {
                    $("#display'.$mypostid.'").html(data);
                })
        });
        $("document").ready(function()
        {
            $.post("comment.php",{commentid: "'.$msg.'",
            newcommentid: "'.$mypostid.'"},function(data)
                {
                    $("#display'.$mypostid.'").html(data);
                })
        });
        </script>

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

我尝试了许多不同的方法来添加ajax加载的回复系统,但似乎没有任何工作

0 个答案:

没有答案