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 Quote 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)"; Quote 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; Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.