title: Query database, explode date to get year, and populate dropdown with unique year
body: <p>I'm trying to populate a form SELECT with OPTIONS from a table in my database. It should display each year once.</p>
  
  <p>eg. If the date fields in the database are 02-09-2010, 10-14-2010, 08-09-2011 :</p>
  
  <p>The dropdown should show:<br />
  2010<br />
  2011</p>
  
  <p>Instead, it shows:<br />
  2010<br />
  2010<br />
  2011</p>
  
  <p>My code:</p>
  
  <pre><code>$result = mysql_query("SELECT date FROM user_history");
  
          $yearoptions = "";
  
          while($row = mysql_fetch_array($result)) {
              $date = $row['date'];
              $yeararray = explode("-", $date);
              $year = array_unique($yeararray);
              $yearoptions .= '&lt;option value="' . $year[2] . '"&gt;'
             . $year[2] . '&lt;/option&gt;';
  </code></pre>
  
  <p>Can anyone see what I'm doing wrong and offer a suggestion?</p>