I have a table that contains "news articles." Each news article is date stamped when it is created (yyyy-mm-dd). I am attempting to allowing people to select and display news articles from a specified year.
I want to provide them with a drop down menu that contains all years that are present in the table.
Example:
the table contains news articles with Release dates of:
2006-12-20
2006-12-23
2007-01-20
2007-03-22
2008-02-01
2008-02-22
I want the drop down to show options to select 2006, 2007, 2008
Currently, with my existing code, it is display all the dates listed above. How can I get it to only show the Year, and then only show each year one time (unique years)?
I can set it up to manually create 2006, 2007, and 2008 using date("Y")-1 in the <option> </option> tags, but would rather have the option values created based on data in the table.
I'm thinking it should involve some type of foreach statement, but can't figure this out.
Any help is very much appreciated!
Thanks in advance.
Here's what I have so far (NOT working). "Release" is the name of the table field that contains the date.
// FORM TO SELECT YEAR OF NEWS RELEASES
print "<form method=\"GET\">";
print "<select name=newsYear onChange=\"document.form.submit()\">";
print "<option selected>"."$_GET[dateYear]"."</option>";
print "<option>-------</option>";
print "<option>";
print date("Y");
print "</option>";
foreach($articleYear as $articleYear){
print "<option>";
print htmlentities($articleYear['Release']);
print "</option>";
}
print "</form>";