如何在MYSQL中从COUNT(*) ORDER BY语句中打印数组的内容


How to print the contents of array from an COUNT(*) ORDER BY Statement in MYSQL

如何打印以下数组的内容:

$sql=
"
SELECT shop_order_location, COUNT(*) FROM shop_orders
LEFT JOIN product
ON shop_orders.shop_order_product_id=product.product_id
WHERE 
DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
BETWEEN '2014-04-01' and '2014-05-01' AND brand = '226' AND shop_order_action = 'Sale'
GROUP BY shop_order_location";
$total = mysql_fetch_array(mysql_query($sql));

这个查询生成如下表

Bawtry      36
Chain       10
Grantham    10
Internet    14

我想传递每个整数结果到一个单独的PHP变量,即$Bawtry = 36, $Chain=10等,然后分别打印每个值。

感谢

* UPDATE *

<?
$sql=
"
SELECT shop_order_location, COUNT(*) FROM shop_orders
LEFT JOIN product
ON shop_orders.shop_order_product_id=product.product_id
WHERE 
DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
BETWEEN '2014-04-01' and '2014-05-01' AND brand = '226' AND shop_order_action = 'Sale'
GROUP BY shop_order_location";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)){
   ${$row['shop_order_location']} = $row['COUNT'];

}
?>

当前状态下的代码似乎没有做任何事情-当我运行php脚本时,它返回一个黑色页面。

我试图将数组的内容传递给单独的变量,即

$Bawtry = 36$Chain = 10

那么我如何分离出数组的结果并将它们传递到单独的变量中呢?

更新2

/*
*   Overall array by shop location counting total pairs
*/
$sql = "SELECT shop_order_location
             , COUNT(*) AS TOTAL
        FROM shop_orders
        LEFT JOIN product ON shop_orders.shop_order_product_id = product.product_id
        WHERE
    DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
        BETWEEN '".$start."' and '".$end."' AND brand = '".$bid."'
        AND shop_order_action = 'Sale'
    GROUP BY shop_order_location";
    $result1 = mysql_query($sql);
    while ($overall = mysql_fetch_array($result1)){
    ${$overall['shop_order_location']} = $overall['TOTAL'];
    } 
/*
*   Mens array - counting pairs of brand 
*/
$sql2 = " SELECT shop_order_location
             , COUNT(*) AS TOTAL
        FROM shop_orders
        LEFT JOIN product ON shop_orders.shop_order_product_id = product.product_id
        WHERE   
    DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
        BETWEEN '".$start."' and '".$end."' AND brand = '".$bid."'
        AND shop_order_action = 'Sale' AND category = 'Mens'
    GROUP BY shop_order_location";
    $result2 = mysql_query($sql2);
    while ($mens = mysql_fetch_array($result2)){
    ${$mens['shop_order_location']} = $mens['TOTAL'];
    }
/*
*   Ladies array - counting pairs of brand
*/  
$sql3 = " SELECT shop_order_location
             , COUNT(*) AS TOTAL
        FROM shop_orders
        LEFT JOIN product ON shop_orders.shop_order_product_id = product.product_id
        WHERE  
    DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
        BETWEEN '".$start."' and '".$end."' AND brand = '".$bid."'
        AND shop_order_action = 'Sale' AND category = 'Ladies'
    GROUP BY shop_order_location";
    $result3 = mysql_query($sql3);
    while ($ladies = mysql_fetch_array($result3)){
    ${$ladies['shop_order_location']} = $ladies['TOTAL'];
    }
/*
*   SUM query - sales total cost
*/
$sql4 = "SELECT SUM(shop_order_price)
        FROM shop_orders
        LEFT JOIN product ON shop_orders.shop_order_product_id = product.product_id
        WHERE  
    DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
        BETWEEN '".$start."' and '".$end."' AND brand = '".$bid."' AND shop_order_action = 'Sale'";
$result4 = mysql_query($sql4) or die(mysql_error());

那么可以这样传递数组结果:

while($row4 = mysql_fetch_array($result4)){
        ?>
        <?
        $showtotal = $row4['SUM(shop_order_price)'] ;
        $showaverage = $row4['SUM(shop_order_price)'] / $total ;
        ?>
                <tr>
                    <td align="center"><strong><?=$brand['name'];?></strong></td>
                    <!-- Bawtry Mens figure -->
                    <td align="center"><?=$mens['Bawtry'];?></td>
                    <!-- Bawtry Ladies figure -->
                    <td align="center"><?=$ladies['Bawtry'];?></td>
                    <!-- Overall Bawtry Figure -->
                    <td align="center"><?=$overall['Bawtry'];?></td>   
$sql = "SELECT shop_order_location
             , COUNT(*) AS TOTAL
        FROM shop_orders
        LEFT JOIN product ON shop_orders.shop_order_product_id = product.product_id
        WHERE DATE(CONCAT(shop_order_year,'-',shop_order_month,'-',shop_order_day))
              BETWEEN '2014-04-01' and '2014-05-01' AND brand = '226' 
              AND shop_order_action = 'Sale'
        GROUP BY shop_order_location";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){
   ${$row['shop_order_location']} = $row['TOTAL']; 
}
echo $Bawtry; //Check assignment
echo ${'Bawtry'}; //It is better to access your variables this way in case there are strings with spaces in the 'shop_order_location' column