dongping4901 2014-07-20 20:50
浏览 5

显示好友请求

I have been working on making a social-network similar to facebook to use on my home server. However, i have come across a problem with displaying friend requests in the notifications tab of the user profile.

<?php
    //Check for notifications script
    $Request = "Requests";
    $Pending = "Pending";
    $nCheck = mysqli_query($Connect,"SELECT * FROM friends WHERE rTo = '$Uname' AND Status = '$Pending'");
    $nNum = mysqli_num_rows($nCheck);
    if($nNum != 0){
        if($nNum === 1){
            $Request = "Request";
        }
        else
        {
            $Request = "Requests";
        }
        echo"<p style=\"font-family: Tahoma; margin-left: 20px;\">You Have <b>$nNum</b> Friend $Request</p><hr />";
        while($row = mysqli_fetch_assoc($nCheck)){
            $dbFrom = $row['rFrom'];
            $dbId = $row['id'];
            $dbStatus = $row['Status'];
            for($i = 0; $i < 1; $i++){
                echo"<p style=\"font-family: Tahoma; margin-left: 20px;\">$dbFrom wants to be your friend <form action=\"\" method=\"POST\"><input type=\"submit\" name=\"A\" value=\"Accept\"></form> <form action=\"\" method=\"POST\"><input type=\"submit\" name=\"D\" value=\"Decline\"></form></p>";
            }
        }
    }
    else
    {
        echo "<p style=\"font-family: Tahoma; margin-left: 20px;\">You Have <b>0</b> Friend $Request</p>";
    }
    ?>

And then this is the form for the Accept / Decline:

<?php
    //Accept/Decline Friend Request Script
    $Accepted = @$_POST['A'];
    $Declined = @$_POST['D'];
    $A = "Accepted";
    $D = "Declined";
    if($Accepted){
        $addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$A' WHERE rTo = '$Uname' AND rFrom = '$dbFrom'");
        header("Location: Notification.php");
    }
    else if($Declined){
        $addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$D' WHERE rTo = '$Uname' AND rFrom = '$dbFrom'");
        header("Location: Notification.php");
    }
    ?>

The problem is that if more than one notification is present, the last notification will be the one that is accepted or declined. Please help, much appreciated.

  • 写回答

3条回答 默认 最新

  • dongzangchui2072 2014-07-20 21:01
    关注

    also try using this

    $A = "Accepted";
    $D = "Declined";
    if($Accepted){
        $addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$A' WHERE  id='$dbId' AND rFrom = '$dbFrom'");
        header("Location: Notification.php");
    }
    else if($Declined){
        $addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$D' WHERE  id='$dbId' AND rFrom = '$dbFrom'");
        header("Location: Notification.php");
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题