Home  >  Article  >  Backend Development  >  php中变量的使用有关问题

php中变量的使用有关问题

WBOY
WBOYOriginal
2016-06-13 11:45:08732browse

php中变量的使用问题
从数据库中获得了各区的销售金额和销售数量,要对数量和金额求和。代码如下:



ob_start();
require_once 'DB.php';
ob_end_clean();
$db=DB::Connect();
$result=$db->QueryLastMonth();
$result1=$db->QueryLastMonthByArea();
$all_sales_amount;
$all_sales_money;
echo 'begin '.$all_sales_amount;
while($row1= sybase_fetch_assoc($result1))
{
?>

switch($row1["areacode"]){
case "E":
echo "华东区";
break;
case "C":
echo "东北区";
break;
case "N":
echo "华北区";
break;
case "W":
echo "西大区(W)";
break;
case "H":
echo "华中区";
break;
case "S":
echo "华南区";
break;
case "F":
echo "华东区(经销)";
break;
case "T":
echo "西大区(T)";
break;
}
?>


--
--


$all_sales_amount+=$row1["area_salesgoodssum"];
$all_sales_money+=$row1["area_salesmoney"];
echo '循环中数量'.$all_sales_amount."金额".$all_sales_money."
";
}
?>






销售简报

总金额:

总数量:


$all_sales_amount为销售数量,$all_sales_money为销售金额。但运行的结果销售数量计算出的结果是错误的,销售金额总是为0(如下)请问上面的代码出了什么问题?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn