如何在mysqli查询中应用条件

时间:2016-05-06 11:28:41

标签: php sql html5 css3 mysqli

我想在我的查询中应用条件,就像我想将一列的值与另一列互换一样。这是我的查询,现在我没有得到如何申请

mysqli_query($connect, "
    select 
        user_pro.User_No, 
        user_pro.Fist_Name, 
        user_pro.Last_Name, 
        user_pro.Designation, 
        user_pro.Profile, 
        user_pro.ProfileDP, 
        user_fndrst.Frnd_SNo, 
        user_fndrst.Rqst_Sender, 
        user_fndrst.Rqst_Receiver, 
        user_fndrst.Rqst_Status 
    from 
        user_profile INNER JOIN user_fndrst ON user_pro.User_No = user_fndrst.Rqst_Sender 
    WHERE 
        user_fndrst.Rqst_Status='1' AND 
        user_fndrst.Rqst_Receiver='$user_id' 
    ORDER BY Frnd_SNo DESC
");

此处“user_pro”表包含用户的详细信息,“user_fndrst”表包含用户的好友请求状态,$ user_id是用户的登录ID。在这里,我希望IF user_fndrst.Rqst_Receiver ='$ user_id'THEN user_fndrst.Rqst_Receiver值更改为user_fndrst.Rqst_Sender。

为此,我坚持从表“user_fndrst”获取用户好友请求状态。

1 个答案:

答案 0 :(得分:0)

您的查询似乎有一些问题。使用此:

SELECT 
    user_pro.User_No, user_pro.Fist_Name, user_pro.Last_Name, user_pro.Designation, user_pro.Profile, user_pro.ProfileDP, user_fndrst.Frnd_SNo, user_fndrst.Rqst_Sender, user_fndrst.Rqst_Receiver, user_fndrst.Rqst_Status 
FROM
    user_profile user_pro
    INNER JOIN user_fndrst ON user_pro.User_No = user_fndrst.Rqst_Sender 
WHERE 
    user_fndrst.Rqst_Status='1' AND user_fndrst.Rqst_Receiver='$user_id' 
ORDER BY 
    user_fndrst.Frnd_SNo DESC