我正在做一個購物cart.i有一個變量$ total.when我添加第一個產品的價格200我得到$總= 200,當我添加第二個產品的價格100當我添加價格400的第三個產品時,我得到$ total = 200100,我得到$ total = 200100400。我想要得到$總數= 700。如何解決這個問題?查找總價值得到一個變量在PHP
session_start();
$ar20=Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'price WHERE id="'.$_SESSION['y'].'" AND prodid="'.$row['id_product'].'" ORDER BY size DESC');
for($i=0;$i < count($ar20);$i++)
{
$test=$test+$ar20[$i]['price'];
}
$row['price'] += $test ;
$row['total'] = $row['price'] * intval($row['quantity']);
如果3個產品則呼應$行[「總」]會得到這個100200300
向我們顯示您的代碼。 – 2010-04-02 05:18:10
在php'+'中做了一個隱式轉換爲數字值。這可能聽起來像一個愚蠢的問題,但你確定你在PHP中添加數字而不是在嵌入在PHP文檔中的Javascript代碼塊中? – leepowers 2010-04-02 05:21:52
session_start(); $ ar20 = Db :: getInstance() - > ExecuteS('SELECT * FROM'._DB_PREFIX _。'WHERE id =''。$ _ SESSION ['y']。'「AND prodid =」'。$ row [' id_product']。'「ORDER BY size DESC'); \t \t \t 爲($ I = 0; $ I <計數($ AR20); $ I ++){ $ 測試= $測試+ $ AR20 [$ i]於[ '價格']; } \t \t \t \t \t \t echo $ test; \t \t \t \t \t \t \t \t \t \t \t \t $行[ '價格'] + = $測試; $ row ['total'] = $ row ['price'] * intval($ row ['quantity']); 如果3個產品然後回顯$行['total']會得到這個100200300 – Hmwd 2010-04-02 05:36:26