0

Hi,

Thanks for checking this out.

My goal is simple. Create a list of all the years that have had articles published in them (so basically every year). I have three unique dates in the date column, 2008-08-20, 2007-08-20, and 2006-08-20.

The code below only returns this as the print_r output;
Array ( [year] => 2008 )

$sql = "SELECT DISTINCT year(date) AS 'year' FROM news ";
$year_query = mysql_query($sql);
$years = mysql_fetch_assoc($year_query);

print_r($years);


foreach ($years as $year){
	echo '<p>' .$year. '</p>';
}

Any help would be great as I have looked all over the net for this.


Thanks again.

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by rickya100
0

pritaeas,

Thank you very much. I had read that page multiple times trying to figure this out. I thought it was in the SQL statement as when I created an array manually with three values and used the foreach loop on it there were no problems.

Anyway thanks for taking the time. I appreciate it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.