I would calculate the total profit of a DataBase for each month using 12 different function [one for each month(yes its probably not a nice solution but I am learning step by step )]
This is the .php code (x12 times)
$January="SELECT JanuaryProfit()"; //Function
echo "<b>January Profit: E</b>";
$January = mysql_query($giugno,$conn)
or die("Query failed: " . mysql_error($conn));
$num_rows=mysql_num_rows($January);
if (! $num_rows)
echo "<p>0</p>";
else {
while ($row = mysql_fetch_row($January)) {
$price=$row[0];
echo "$price";
};
}
Function JanuaryProfit() is declared this way [MySQL]:
BEGIN
DECLARE PriceTOT FLOAT;
SELECT SUM(o.PrezzoTot) INTO PriceTOT
FROM orders o
WHERE o.Data BETWEEN '2012-01-01' AND '2012-01-31';
RETURN PriceTOT;
END
And so I've declared singularly february,march,...,december.
I wouldn't paste 12 times the first code into the .php page.I've tried using a for cicle that use different function every time but i cannot figure how to solve this,correctly.Any suggest?
All I wanna do by now is changing the php part only,using a loop.
LASTDAY()function which is probably your stumbling block.