0
I have a table like this:
data |id
2017-02-01 00:00:00|1
2017-02-01 00:00:00|5
2017-04-01 00:00:00|2
2018-02-01 00:00:00|3
2018-04-01 00:00:00|4
Then I make a query with PHP in Mysql that brings me
SELECT id, data
FROM orders
GROUP BY data
and brings in php
foreach($results as $row){
echo date('m',$row->data).'<br/>';
}
the above result is:
02
04
02
04
But I wanted him to bring in groups every year:
2017
02
04
2018
02
04
he is bringing the results empty, I made a echo $mes and $year, came straight, but in the interval, came empty
– Leandro Marzullo
actually, it Apare as a result: year
– Leandro Marzullo
Well test this new (edited). if it goes wrong you can show me which function or method you use to get
$results
– Atila Silva
Perfect! Gave straight, thanks!!!
– Leandro Marzullo
The manipulations that PHP has with arrays are the most powerful tools that the language has. The programmer who dominates these manipulations will have a productivity above average. ;)
– Atila Silva
I’ll take a look at it, I’m still beginner, vlw!!
– Leandro Marzullo
PHP Recommendation - Object-oriented programming - Pablo Dall'Oglio. The first chapter brings a practical approach to value manipulation tools.
– Atila Silva
only had a problem actually, if they have 2 months of the same year only appears 1 month, ex: dates 02/2018, 03/2018 and 02/2017, only appears 02/2018 and 02/2017
– Leandro Marzullo
I edited the answer. Well it would be nice if you provide a
var_dump($results)
– Atila Silva
Show, now gave straight, thank you very much!
– Leandro Marzullo