0
I have the following code below and I would like it to return me the sum of the values separated by the said month of release in PHP, because it is returning the current month.
Example:
DATA VALOR 21/01/2018 200.00 23/02/2018 200.00 25/01/2018 200.00
JANUARY: 400.00 FEBRUARY: 200.00
And so on. Someone who can help me?
<?php
$conn = mysqli_connect('localhost','root','root','sistema');
$resultado = mysqli_query($conn, "SELECT sum(total) FROM pedidos GROUP BY YEAR(post_at), MONTH(post_at) ;" );
$linhas = mysqli_num_rows($resultado);
while($linhas = mysqli_fetch_array($resultado)){
echo date("m ") . 'R$: ' . $linhas[ 'sum(total)'] .'<br/>';
?>
<?php
}
?>
Do you want to get the values grouped by month? In the case of 01/01 to 31/01, you want the sum of that month’s records, and so on?
– Mauro Alexandre
Yes, separating them by month. and returning the month of the said sum. In this case my code already groups, but does not return me the month of the sum. me returns the month but not the month of release but the current month. Example: 06 R$: 200 06 R$: 116 06 R$: 100 06 R$: 200
– Nyl Guedes
The idea would be to create a column always displaying the total sum of the month?
– Inácio Régis
The code brings me yes the sum, grouped. but the grouping returns me a month only for all. The month of June. Where should return other months. EXAMPLE: Jun - R$: 200 Jun - R$: 116 Jun- R$: 100 Jun- R$: 200
– Nyl Guedes
You can put the result to execute
SELECT sum(total) FROM pedidos GROUP BY YEAR(post_at), MONTH(post_at)
direct on phpmyadmin with apost_at
for example ?– Isac
The problem is in
date("m")
, this will always return the current date and not the date of the bank’s records.– Woss
And how to return the date of the records?
– Nyl Guedes
Solved, thanks to all the comments, I solved with a foreach and picking the variable with a strtotime.
– Nyl Guedes