简体   繁体   English

简单数据库查询的问题

[英]issues with simple database query

I have issues with this pretty simple database query. 我有这个非常简单的数据库查询问题。 The opening if-condition is true and working. 开头的if条件为真且有效。

The problem comes with the if/if/else inside. 问题来自内部的if / if / else。 The second statement, when the active user has some connections, but the profile he is visiting does not, is working. 第二条语句是当活动用户具有某些连接但他正在访问的个人资料不起作用时。 Results in "invite to your crew". 结果为“邀请您的船员”。

But if the first state of nature is true, when neither the active user nor the profile owner has connections, my query isn't working. 但是,如果第一个自然状态为true,那么当活动用户和配置文件所有者都没有连接时,我的查询将无法正常工作。 It will always result in the else statement ("join crew"), which should only happen when the profile owner has at least one connection ($countProfileCon!==0), in that case it won't matter how many connections the active user has. 它将始终导致else语句(“ join crew”),仅当配置文件所有者具有至少一个连接($ countProfileCon!== 0)时才会发生,在这种情况下,活动的连接数无关紧要用户拥有。

I can't see why. 我不明白为什么。

    if ($countCurrent==0 && $countFormer==0) {


        $activeConnectionQuery = $DBcon->query("SELECT * FROM tbl_current_userconnections WHERE user_id=".$_SESSION['userSession']);
        $countActiveCon=$activeConnectionQuery->num_rows;

        $profileConnectionQuery = $DBcon->query("SELECT * FROM tbl_current_userconnections WHERE user_id=".$_GET['user']);
        $countProfileCon=$profileConnectionQuery->num_rows;



        if ($countActiveCon==0 && $countProfileCon==0) {
            $connect = "<p>create a crew</p>";
        }

        if ($countActiveCon!==0 && $countProfileCon==0) {
            $connect = "<p>invite to your crew</p>";
        } 

        else {
            $connect = "<p>join crew</p>";
        }
    }

tbl_current_userconnections looks like this, when the problem occurs: 发生问题时,tbl_current_userconnections如下所示:

user_id                 connection_id
----------------        ----------------

(it's empty, obviously) (很明显是空的)

I think you are missing the "else" keyword in second condition. 我认为您在第二种情况下缺少“ else”关键字。

if ($countActiveCon==0 && $countProfileCon==0) {
    $connect = "<p>create a crew</p>";
}

elseif ($countActiveCon!==0 && $countProfileCon==0) {
    $connect = "<p>invite to your crew</p>";
} 

else {
    $connect = "<p>join crew</p>";
}

Your first condition works fine. 您的第一个条件很好。 But because of missing elseif it overrides your variable, because second condition is evaluated as false. 但是由于缺少elseif,它会覆盖您的变量,因为第二个条件被评估为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM