Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
public function daily_sales($date)
	{
		$sql = "SELECT *
				FROM sales
				WHERE DATE(`sale_date_paid`) = ?
				ORDER BY sale_date_paid DESC";
		return $this->getRows($sql, [$date]);
	}//end daily_sales


What I have tried:

public function daily_sales($date)
	{
		$sql = "SELECT *
				FROM sales
				WHERE DATE(`sale_date_paid`) = ?
				ORDER BY sale_date_paid DESC";
		return $this->getRows($sql, [$date]);
	}//end daily_sales

	public function monthly_sales($date){
		//kailangan ma pasa rito yung month at year
		$sql = "SELECT * FROM `sales` WHERE `sales`.`sale_date_paid` LIKE '$date%'";
		return $this->getRows($sql,[$date]);
	}
Posted
Updated 11-Mar-19 8:33am
v2

1 solution

The key to doing reports over periods of time is to utilize the aggregate and functions in conjunction with GROUP BY

Please note that I have not formatted this for any particular version of SQL, and I also do not not know what column in your table contains the amounts of sale. You may need to adjust for your situation
SQL
SELECT   YEAR(sale_date_paid), MONTH(sale_date_paid), SUM(OrderTotal)
FROM     sales
GROUP BY YEAR(sale_date_paid), MONTH(sale_date_paid)
ORDER BY YEAR(sale_date_paid), MONTH(sale_date_paid)

Reference: MySQL sum() with group by - w3resource[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900