The usage of variables in php obtains the sales amount and sales quantity of each region from the database. sum the quantity and amount. The code is as follows: & lt ;? PHPob_start (); require_once & nbsp; DB. php; ob_end_clean (); & nbsp; $ dbDB: Connect (); $ result $ db-& gt; QueryLastMonth (); & use of variables in php
Obtain the sales amount and sales quantity of each region from the database, and sum the quantity and amount. The code is as follows:
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 "East China ";
Break;
Case "C ":
Echo "Northeast region ";
Break;
Case "N ":
Echo "North China ";
Break;
Case "W ":
Echo "West Region (W )";
Break;
Case "H ":
Echo "Central China ";
Break;
Case "S ":
Echo "South China ";
Break;
Case "F ":
Echo "East China (distribution )";
Break;
Case "T ":
Echo "West Region (T )";
Break;
}
?>
--
--
$ All_sales_amount + = $ row1 ["area_salesgoodssum"];
$ All_sales_money + = $ row1 ["area_salesmoney"];
Echo 'number in a loop '. $ all_sales_amount. "amount". $ all_sales_money ."
";
}
?>
Sales briefing
Total amount:
Total quantity:
$ All_sales_amount indicates the sales quantity, and $ all_sales_money indicates the sales amount. However, the result of calculating the sales quantity in the running result is incorrect. the sales amount is always 0 (as shown below). What is the problem with the above code?
Share: More
------ Solution --------------------
$ All_sales_amount + = $ row1 ["area_salesgoodssum"]; // 43547
That's right.
$ Row1 ["area_salesmoneysum"]
Sum $ all_sales_money + = $ row1 ["area_salesmoney"];
$ Row1 ["area_salesmoneysum"] is the same as $ row1 ["area_salesmoney?
You didn't say that. I can't say anything anymore.
------ Solution --------------------
$ All_sales_money + = $ row1 ["area_salesmoney"]; changed to $ all_sales_money + = $ row1 ["area_salesmoneysum"] should be OK.