# How to calculate monthly total at the end of every month in php?

 mksharmil02:24:13 I have the following code which queries a database and presents the results: `````` ='2012-01-28' AND date1<='2013-02-28' and tax_name='C.S.T. 4% ON SCRAP' and tin='Applied For' GROUP BY month(date1), day(date1), id "; \$qt=mysql_query(\$query); echo mysql_error(); echo "
No. of orders Date Month
(dt)
Year
(dt2)
Daily Sale
\$nt[num_orders] \$nt[date1] \$nt[month1] \$nt[month2]
Daily Total\$nt[daily_total]
\$C subtotal
\$q gtotal
\$p
"; while(\$nt=mysql_fetch_array(\$qt)){ echo ""; echo "<â€¦ echo ""; \$query1="SELECT * FROM `sale` where date1>='2012-01-28' AND date1<='2013-01-31' and tax_name='C.S.T. 4% ON SCRAP' and tin='Applied For' and gtotal "; \$qt1=mysql_query(\$query1); echo mysql_error(); \$num=mysql_num_rows(\$qt1); if(\$num) { \$p=0; \$q=0; while(\$nt1=mysql_fetch_array(\$qt1)){ \$p=\$p+\$nt1['gtotal']; \$q=\$q+\$nt1['subtotal'];}} echo ""; echo ""; ?>`````` It shows daily total But I have hundreds of data items to calculate. Suppose I have 5 data items in January, they all should be seen in 5 rows and at the end of month there should be the month total and so on until 12 months. Please help smo123402-26-2013 You can use group by query in date field. mksharmil02-27-2013 Thanks a lot @smo1234. its done!!! Even more powerfull as I expected.