爲什麼如果和其他兩個條件都內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";
}
}
這不是說,如果和其他正在執行。那就是你要調用兩次函數並檢查你在else語句中改變的值(第一次調用),這會使你在第二次調用中陷入if語句。 – Tarek
我已添加完整的代碼,看看@jDo –
@hassanraza酷酷。也得到了答案,我看到:) – jDo