如何将好友表中的状态从待定状态更新为已接受状态?

时间:2011-07-11 10:51:31

标签: php system friend

经过大量的谷歌搜索,我实现了发送添加为朋友的请求,说用户a向用户b发送朋友请求,用户b登录他将看到来自用户的请求...说只显示他的名字当用户点击该名称时,会打开一个对话框,询问用户是否接受或拒绝该请求,我现在面临的问题是我无法找到如何从待处理状态更新好友表状态列接受即当显示好友请求被接受的警报消息时,好友表的状态列应该从待处理更新为已接受,如果被拒绝则应将状态列更新为已拒绝

请指导我完成这个

<script>

        $(function(){
            $("#shortthemes a").click(function(e){
                e.preventDefault();
                $("link#theme").attr('href',$(this).attr('href'));
                $("#shortthemes a").removeClass('selected');
                $(this).addClass('selected');
            });
        });


        function tstconfirm(){
            smoke.confirm('Confirm as Friend !',function(e){
                if (e){
                    alert('Friend Request Accepted');

                }else{
                    alert('Friend Request Rejected');
                }
            });
        }

</script>

1 个答案:

答案 0 :(得分:0)

在处理Post-request并更新数据库的PHP文件中发帖:

  <script>

    $(function(){
        $("#shortthemes a").click(function(e){
            e.preventDefault();
            $("link#theme").attr('href',$(this).attr('href'));
            $("#shortthemes a").removeClass('selected');
            $(this).addClass('selected');
        });
    });


    function tstconfirm(){
        smoke.confirm('Confirm as Friend !',function(e){
            if (e){
                alert('Friend Request Accepted');
                $.post('friend_actions.php', {pk_friendrequest_id: fk_partner_id.val(), action: 'accept_request'}, function(data){  if (data.length > 100) { alert(data); } else { window.location.replace(data) }; });

            }else{
                alert('Friend Request Rejected');
                $.post('friend_actions.php', {pk_friendrequest_id: fk_partner_id.val(), action: 'reject_request'}, function(data){  if (data.length > 100) { alert(data); } else { window.location.replace(data) }; });

            }
        });
    }

在你的friend_actions.php中添加:

    if ($_POST['action'] == 'accept_request') {
     $qry = "UPDATE friend_request SET status = 'Accepted' WHERE pk_friendrequest_id = '.$_POST['pk_friendrequest_id'];

     $db = mysql_connect('YOUR_DB_ADDRESS','YOUR_DB_USER','YOUR_DB_PASS') or die("Database error");
     mysql_select_db('YOUR_DB', $db);

     mysql_query($qry);     

echo "index.php"; //Or any other page where you want the user to go after completion
    }

    if ($_POST['action'] == 'reject_request') {
     $qry = "UPDATE friend_request SET status = 'Rejected' WHERE pk_friendrequest_id = '.$_POST['pk_friendrequest_id'];

     $db = mysql_connect('YOUR_DB_ADDRESS','YOUR_DB_USER','YOUR_DB_PASS') or die("Database error");
     mysql_select_db('YOUR_DB', $db);

     mysql_query($qry);     

echo "index.php"; //Or any other page where you want the user to go after completion
    }

PHP文件返回一个URL。 Javascript检查响应是否为&lt; 100个字符(否则它可能是一个错误,它会提示它进行调试),如果是,它会将您重定向到URL。