PHP query for totals of products for last six months
Posted
by
user2260925
on Stack Overflow
See other posts from Stack Overflow
or by user2260925
Published on 2013-06-26T16:19:36Z
Indexed on
2013/06/26
16:21 UTC
Read the original article
Hit count: 135
php
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.
© Stack Overflow or respective owner