0

我有以下关于添加新朋友的脚本。它在两种情况下都可以正常工作,并且在一侧有问题。例如,如果 A 向 B 和 C 发送好友请求。当 B 接受他的请求时,C 仍然没有接受。如果 C '等待批准'正在工作。条件 1 不起作用。意味着即使 A 是您的朋友,您仍然可以发送请求。下面是脚本:

<?php
$querToCheck    =   "SELECT * FROM friends WHERE accepted = '2' AND ((user_one = '$activeID' AND user_two = '$fid') OR (user_one = '$fid' AND user_two = '$activeID' ) )";

$resToCheck     =   mysql_query($querToCheck);

if(mysql_num_rows($resToCheck)==2)
{
    $addFriend  =   "Friends";      
}
else
{
    $querToCheck    =   "SELECT * FROM friends WHERE accepted = '1' AND ((user_one = '$activeID' AND user_two = '$fid') OR (user_one = '$fid' AND user_two = '$activeID' ) )";

    $resToCheck     =   mysql_query($querToCheck);

    if(mysql_num_rows($resToCheck)==1)
    {
        $addFriend  =   "Waiting For Approval";
    }
    else
    {
        $querToCheck    =   "SELECT * FROM friends WHERE accepted = '0' AND ((user_one = '$activeID' AND user_two = '$fid') OR (user_one = '$fid' AND user_two = '$activeID' ) )";
        $resToCheck     =   mysql_query($querToCheck);

        if(mysql_num_rows($resToCheck)==0)
        {
            $addFriend  =   '<a href="addAsFriend.php?sid='.$row['id'].'" style="color:#FFFFFF;font-size:14px;">Add As Friend</a>';
        }
    }
}
}
?>
4

1 回答 1

0

我认为您必须检查accepted列值而不是检查返回的行数

<?php
$addFriend = "";
$querToCheck = mysql_query("SELECT * FROM friends WHERE (user_one = '$activeID' AND user_two = '$fid') OR (user_one = '$fid' AND user_two = '$activeID' ) ");
if(mysql_num_rows($querToCheck) > 0)
{
    $row = mysql_fetch_array($querToCheck);
    $accepted = $row['accepted'];

    if($accepted == 1)
    {
        $addFriend  = "Waiting For Approval";
    } else if($accepted == 2)
    {
        $addFriend  = "Friends";  
    } 
}
else
{
    $addFriend  = '<a href="addAsFriend.php?sid='.$row['id'].'" style="color:#FFFFFF;font-size:14px;">Add As Friend</a>'; 
}
?>
于 2013-06-17T23:27:55.730 回答