2013-10-13 55 views
0

它只能檢測到第一個條件,任何其他條件都不會工作。 xpath是正確的。如果我沒有循環,它會工作。我在這裏做錯了什麼?循環遍歷isEmpty

$pricediscount = ""; 
$chinesename =""; 


if (empty($pricediscount)){ 
     $pricediscount = (@$xpath->query("//*[@id='J_PromoPrice']/div/strong/text()")->item(0)->nodeValue); 
    }elseif(empty($pricediscount)){ 
     $pricediscount = (@$xpath->query("//*[@id='J_StrPrice']/em[2]")->item(0)->nodeValue); 
    }elseif(empty($pricediscount)){ 
     $pricediscount = (@$xpath->query("//*[@id='J_PromoBox']/strong")->item(0)->nodeValue); 
    }elseif(empty($pricediscount)){ 
     $pricediscount = (@$xpath->query("//*[@id='J_StrPrice']")->item(0)->nodeValue); 
    }else{ 
     $pricediscount = "NA"; 
    } 
+2

那麼,你正在測試相同的條件3次......你想要做什麼? – elclanrs

+0

如果第一個else如果是空的,那就去其他的if – CodeGuru

+0

如果第一個是空的,所有其他的都是空的,你一遍又一遍地測試同樣的東西......我不明白你的邏輯是什麼。 – elclanrs

回答

2

你曾經只運行第一if語句,因爲它永遠是真實的,因此else塊將不進行評估。嘗試將elseifelse語句更改爲if