我的脚本显示添加为朋友,即使用户是我的朋友

时间:2013-06-17 23:07:08

标签: php

我在下面有关于添加新朋友的脚本。它在两种情况下正常工作,一方面有问题。例如,如果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>';
        }
    }
}
}
?>

1 个答案:

答案 0 :(得分: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>'; 
}
?>