2016-04-22 141 views
-1

爲什麼如果其他兩個條件都內if($flw){ ... }如果和其他兩個條件PHP

執行執行程序的內部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"; 
    } 
} 
+0

這不是說,如果和其他正在執行。那就是你要調用兩次函數並檢查你在else語句中改變的值(第一次調用),這會使你在第二次調用中陷入if語句。 – Tarek

+0

我已添加完整的代碼,看看@jDo –

+0

@hassanraza酷酷。也得到了答案,我看到:) – jDo

回答

1
if (something) { //The parent IF 

    if (something else) { //The child IF 
    //do something 
    } 

    else { //Runs when the child IF is not true. 
    //do another 
    } 

} 

完全,你可以簡單地說這個類:其他內不是爲父母的人。這是爲兄弟

+0

但成爲孩子後,如果真的,程序應該終止,但它會去其他條件,爲什麼? –

+0

@hassanraza,這是不可能的。請逐步添加一些硬編碼的回聲,看看發生了什麼 – Mojtaba