日期:2014-05-16  浏览次数:20619 次

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

<?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))
{
  ?>
  <tr>
                <th data-options="field:'itemid',width:80"><?php 
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;
}
?></th>
                <th data-options="field:'productid',width:80"><?php echo $row1["area_salesgoodssum"]?></th>
                <th data-options="field:'listprice',width:100,align:'right'"><?php echo $row1["area_salesmoneysum"]?></th>
                <th data-options="field:'unitcost',width:80,align:'right'">--</th>
                <th data-options="field:'status',width:60,align:'center'">--</th>
            </tr>

<?php 
 $all_sales_amount+=$row1["area_salesgoodssum"];
 $all_sales_money+=$row1["area_salesmoney"];
 echo '循环中数量'.$all_sales_amount."金额".$all_sales_money."<br>";
 }
 ?>
        </thead>
    </table>
</div>


    <div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:160px;background:#fafafa;border:1px solid #ccc;margin-top:10px">
        <div id="title" style="padding:5px;background:#ccc;color:#FA0000">销售简报<?php ?></div>
<span>总金额:<?php echo $all_sales_money; ?> </span><br>
<span>总数量:<?php echo  $all_sales_amount?> </span>


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