Questions about the use of variables in PHP

Source: Internet
Author: User
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";
Case "C":
echo "North East District";
Case "N":
echo "North China area";
Case "W":
echo "West Region (W)";
Case "H":
echo "Central China";
Case "S":
echo "Southern Region";
Case "F":
echo "East East (distribution)";
Case "T":
echo "West Region (T)";


$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

$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.

$all _sales_money+= $row 1["Area_salesmoney"]; Change to $all_sales_money+= $row 1["Area_salesmoneysum"] should be OK.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.