2016-09-16 74 views
1

我從9xx項目的數據庫中獲得價格。 我添加此顯示項目頁面。使用Foreach $ rows = $ row。 vprice是我sellingprice和dprice是我dealerprice某些行不計入foreach循環

$commisionrate = 30; 
$commisionfee = 100; 
$fee = $row['dprice'] + $commisionfee;//+100 
$x = $row['dprice']; 
$y = $x * $commisionrate/100; 
$z = $x + $y; 
$rate = $z;//(100*30%)+100 
if (($rate > $row['vprice']) && ($fee < $row['vprice'])){ 
    echo $fee; 
}elseif (($fee > $row['vprice']) && ($rate < $row['vprice'])){ 
    echo $rate; 
}elseif ($row['dprice']=$row['vprice']){ 
    echo $row['dprice']; 
} 

,當我重新檢查所有,我發現$row['dprice']幾個項目不計,並仍然受到舊價格顯示。實例是假的:我發現vprice爲188計算後80 dprice應該是104,但不改變與仍留在80

+1

表現出一定的輸出... –

+0

可能還需要補充一點,拉這些查詢數據庫中的值,聽起來很愚蠢,但是確保你確實拉動了所有你認爲正在拉動的行 – WillardSolutions

+3

'$ row ['dprice'] = $ row ['vprice']''是'$ row ['' dprice'] == $ row ['vprice']' –

回答

1
$commisionrate = 30; 
$commisionfee = 100; 
$fee = $row['dprice'] + $commisionfee;//+100 
$x = $row['dprice']; 
$y = $x * $commisionrate/100; 
$rate = $x + $y; 

// You don't need to put nested brackets, it very simple condition  
if ($rate > $row['vprice'] && $fee < $row['vprice']){ 
    echo "fee: " . $fee; //add some hint words, so you know which condition fires 

// You don't need to put nested brackets, it very simple condition 
} elseif ($fee > $row['vprice'] && $rate < $row['vprice']) { 
    echo "rate: " . echo $rate; 

// USE double `==`, because when single `=` used, the condition always returns true and you're confused by your result 
} elseif ($row['dprice'] == $row['vprice']) { 
    echo "row[\'dprice\']: " . $row['dprice']; 

// add last else 
} else { 
    // this is helpful for debugging of your possible output, regardless you are awaiting some output here 
} 
+0

嗨。我不會混淆結果。我只忘記再添加1個條件,如果費率和費用低於vprice,那麼會選擇使用費率價格。 –