title: Return month and date only once using mysql and php
body: <p>I am creating a archive of posts which I want to create archive links for when the articles were created in year / month format.</p>
  
  <p>Created dates in database are stored in <code>YYYY-MM-DD</code> format and have written this so far.</p>
  
  <pre><code>$archive =
    mysql_query("SELECT DISTINCT DateCreated FROM blog ORDER by DateCreated")
    or die("Could not execute query");
  
  while($row = mysql_fetch_array($archive) ){ 
    $Date = explode("-", $row["DateCreated"]);
    $Year = $Date[0];
    $Month = $Date[1];
  
    // Months of the year.
    $MonthName = array(
      "01" =&gt; "JAN",
      "02" =&gt; "FEB", 
      "03" =&gt; "MAR",
      "04" =&gt; "APR",
      "05" =&gt; "MAY",
      "06" =&gt; "JUN",
      "07" =&gt; "JUL",
      "08" =&gt; "AUG",
      "09" =&gt; "SEP",
      "10" =&gt; "OCT",
      "11" =&gt; "NOV",
      "12" =&gt; "DEC");    
  
   $archiveData .=
     "&lt;a href='archive.php?".$Year."-".$Month.
     "'&gt;".$MonthName[$Month]."-".$Year."&lt;/a&gt;&lt;br /&gt;"; 
  }
  </code></pre>
  
  <p>If I have these dates stored in my database</p>
  
  <pre><code>2012-04-07, 
  2012-05-02, 
  2012-05-13, 
  2012-02-22, 
  </code></pre>
  
  <p>Then the above code produces links as</p>
  
  <pre><code>FEB-2012, 
  APR-2012, 
  MAY-2012, 
  MAY-2012, 
  </code></pre>
  
  <p>It shows the months that have already been added, what I need to do is limit it to show it only once.</p>
  
  <p>I think I need to change the query but not sure how to get the result I require any help would be appreciated.</p>