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

发布于 2024-11-19 05:02:36 字数 893 浏览 10 评论 0原文

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

请指导我完成此操作

<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>

After a lot googling i acheived to send a request to add as friend, say user a sends a friend request to user b and user b logs in he will see the request from user a ... say only his name is displayed when the user clicks on that name a dialog box is opened which will ask the user whether to accpet or reject that request, the problem i am facing right now is i am not able to find how can i update the friends table status column from pending to accepted i.e when the alert message Friend request accepted is displayed the status column of friends table should be updated from pending to accepted and if rejected it should update the status column as rejected

please guide me through this

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美男兮 2024-11-26 05:02:36

对 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 检查响应是否小于 100 个字符(否则可能是一个错误,并警告它进行调试),如果是,它会将您重定向到 URL。

Do a post to a PHP-file which handles your Post-request and updates the database:

  <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) }; });

            }
        });
    }

In your friend_actions.php add:

    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
    }

The PHP-file returns a URL. The Javascript checks if the response is <100 characters (else it's probably an error and it alerts it for debugging) and if so, it redirects you to the URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文