Pregunta

Table articles

id - content - ins_dt
1 - lorem ipsum1 - 2013-01-09
2 - lorem ipsum2 - 2013-02-08
3 - lorem ipsum3 - 2012-11-03
4 - lorem ipsum4 - 2011-01-20
5 - lorem ipsum5 - 2011-12-13
6 - lorem ipsum6 - 2010-05-12

With query

SELECT ins_dt FROM articles ORDER BY ins_dt DESC;

I get this: (http://sqlfiddle.com/#!2/fc9ea6/5)

"2013 2013 2012 2011 2011 2010" 

But I need this:

"2013 2012 2011 2010"
¿Fue útil?

Solución 2

You can use simple SQL query

SELECT GROUP_CONCAT(DISTINCT YEAR(ins_dt)) AS `year` 
FROM articles 
ORDER BY ins_dt DESC;

Here is the sample and demo: http://sqlfiddle.com/#!2/fc9ea6/3

Otros consejos

Whatever the values you are getting store them in array

then $finaldata = array_unique($yourarray);

As you have the data in an array, you can easily use Array unique in your code, which will give you an array with only unique values in it.

Alternately, you could change your SQL to only pull the data you need from the table itself like this:

select distinct year from (select date_format(ins_dt, '%Y') from tableArticles) myData)

try sort http://php.net/manual/en/function.sort.php

sort($myarr['ins_dt'], SORT_NUMERIC); 
 print_r($myarr);

a little searching effort could land you on great links like this one http://php.net/manual/en/array.sorting.php

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top