在 PHP 中执行 if 和 else 这两个条件


executing if and else both condition in PHP

为什么否则两个条件都在if($flw){ ... }内执行

执行程序的内部if条件后,else条件也在执行。

这是我正在使用的类

class follow extends 'Thread{
public $follow;
public $query;
public function connect(){
   $my = new 'mysqli(SQLHOST, SQLUSER, SQLPASS, SQLDB);
   return $my;
}
public function run(){}
/*****************************************
*sql queries  related to follow system   *
*@param $x follower $y following         *
******************************************/
public function followSql($x, $y){
    $this->query = array(

        'follow' => "INSERT INTO follow(userid, following) VALUES('$x','$y')",
        'unfollow' => "DELETE FROM follow WHERE userid ='$x' AND following='$y'",
        'following' => "SELECT followid FROM follow WHERE userid='".$x."' AND following='".$y."'"
    );
    return $this->query;
}
/*****************************
*  to follow user            *
*  @param $query sql query   *
*****************************/
public function followDoUndo($q){
    try{
        if($this->connect()){
         mysqli_query($this->connect(), $q);
        }
    }catch(Exception $ex){
        var_dump($ex);
    }
}
/***********************************
*  to show user folllowing or not  *
*  @param $query sql query         *
************************************/
public function following($q){
    try{
        if($this->connect()){
            $result = mysqli_query($this->connect(), $q);
            if (is_object($result)) {
                    if(mysqli_num_rows($result)>0)
                        $this->follow = TRUE;
            }
         return $this->follow;
        }

}catch(Exception $ex){
            var_dump($ex);
        }
    }
}

if($_SERVER["REQUEST_METHOD"] == "POST" ){
    $flw = $_POST["flw"];
}

if($flw){
    if($follow->following($follow->followSql($uid,$ud)['following'])){
        $follow->followDoUndo($follow->followSql($uid,$ud)['unfollow']);
        $showText = "+ follow";
    }
    else{
        $follow->followDoUndo($follow->followSql($uid, $ud)['follow']);
        $showText = "following";
    }   
}
if (something) { //The parent IF
  if (something else) { //The child IF
    //do something
  }
  else { //Runs when the child IF is not true.
    //do another
  }
}

完全,你可以简单地这样说:内在的"其他"不是"父母的"其他"。这是为了兄弟姐妹