PHP query for totals of products for last six months
- by user2260925
I need to get the figures for the last six months from my orders table. The table has the following fields: qty, product, price, code,
The format of the report must be as follows:
Month: Jan Feb Mar Apr May June
Product1 7 5 4 6 8 9
Product2 8 3 1 4 7 7
Product3 5 4 1 7 7 6
My current code gets the figures for one month only:
"SELECT product,building, SUM(qty) AS 'month1' FROM sh_orders WHERE MONTH(order_date) = MONTH(CURDATE()) GROUP BY product";
The code to show it is:
echo "
<td> ". $row['product']. "</td>
<td> ". $row['month1']. "</td>;
Any help is greatly appreciated.