Usage of variables in PHP
The sales amount and quantity of each district are obtained from the database, and the quantity and amount are summed. The code is as follows:
Ob_start ();
Require_once ' db.php ';
Ob_end_clean ();
$db =db::connect ();
$result = $db->querylastmonth ();
$result 1= $db->querylastmonthbyarea ();
$all _sales_amount;
$all _sales_money;
echo ' begin '. $all _sales_amount;
while ($row 1= Sybase_fetch_assoc ($result 1))
{
?>
Switch ($row 1["AreaCode"]) {
Case "E":
echo "East";
Break
Case "C":
echo "North East District";
Break
Case "N":
echo "North China area";
Break
Case "W":
echo "West Region (W)";
Break
Case "H":
echo "Central China";
Break
Case "S":
echo "Southern Region";
Break
Case "F":
echo "East East (distribution)";
Break
Case "T":
echo "West Region (T)";
Break
}
?>
--
--
$all _sales_amount+= $row 1["Area_salesgoodssum"];
$all _sales_money+= $row 1["Area_salesmoney"];
Echo ' Number of loops '. $all _sales_amount. " Amount ". $all _sales_money."
";
}
?>
Sales Briefing
Total Amount:
Total Quantity:
$all _sales_amount is the number of sales, $all _sales_money is the sales amount. But the result of running the sales quantity calculated the result is wrong, the sales amount is always 0 (below) What is wrong with the above code?
Share to: more
------Solution--------------------
$all _sales_amount+= $row 1["Area_salesgoodssum"]; 43547
That's right.
The amount column shows $row 1["Area_salesmoneysum"]
Sum $all _sales_money+= $row 1["Area_salesmoney"];
$row 1["Area_salesmoneysum" and $row 1["Area_salesmoney" are the same?
You didn't say anything, I'm not saying much.
------Solution--------------------
$all _sales_money+= $row 1["Area_salesmoney"]; Change to $all_sales_money+= $row 1["Area_salesmoneysum"] should be OK.