Darkmatter5 Posted October 30, 2008 Share Posted October 30, 2008 If I had an array created from a query of mysql, that returned a year column. How can I list each instance of each unique year. Example. Table: item_id year 1 2008 2 2004 3 2008 4 2001 5 2004 how can I make a list that would look like this? 2001 2004 2008 Link to comment https://forums.phpfreaks.com/topic/130726-solved-extracting-instances-of-a-string-in-an-array/ Share on other sites More sharing options...
gaza165 Posted October 30, 2008 Share Posted October 30, 2008 In your sql query just use group by $sql = "SELECT year FROM database_name GROUP BY YEAR(year)"; Link to comment https://forums.phpfreaks.com/topic/130726-solved-extracting-instances-of-a-string-in-an-array/#findComment-678418 Share on other sites More sharing options...
o3d Posted October 30, 2008 Share Posted October 30, 2008 or you could use : SELECT DISTINCT year FROM tablename; Link to comment https://forums.phpfreaks.com/topic/130726-solved-extracting-instances-of-a-string-in-an-array/#findComment-678470 Share on other sites More sharing options...
Darkmatter5 Posted October 30, 2008 Author Share Posted October 30, 2008 Thanks both for the input! Link to comment https://forums.phpfreaks.com/topic/130726-solved-extracting-instances-of-a-string-in-an-array/#findComment-678476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.