How would I print the contents of the following array :
$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));
...
This query generates the following table
Bawtry 36
Chain 10
Grantham 10
Internet 14
I want to pass each integer result into a separate PHP variable, i.e. $Bawtry = 36, $Chain=10 etc. and then print each value separately.
Thanks
* 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'];
}
?>
This code in it's current state isn't appearing to do anything - when I run the php script, it returns a black page.
I'm trying to pass the contents of the array to separate variables, i.e.
$Bawtry = 36 $Chain = 10
So how would I separate out the results of the array and pass them into separate variables?
UPDATE 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());
So could the array results be passed like so :
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>