title: Archive by year and month
body: <p>I'm trying to build a year\month archive.</p>
  
  <p>It refuses to output what i want so i'm hoping one of you might push me in the right direction.</p>
  
  <p>I want to sort by year, and show the months for each year ( if exists) and output it like this:</p>
  
  <pre><code>2012
   - June
   - August 
  2011
   - July
  </code></pre>
  
  <p>my code is this :</p>
  
  <pre><code>$query = "SELECT * FROM article WHERE full_name ='$safe_name' group by year, month";
  $result = mysql_query($query) or die(mysql_error());
  while($row = mysql_fetch_assoc($result)) {
  $year = $row['year'];
  $month = $row['month'];
  echo "&lt;ul class='year'&gt;&lt;li&gt;&lt;a&gt;{$year}&lt;/a&gt;";
  echo "&lt;ul class='months'&gt;&lt;li&gt;&lt;a&gt;{$month}&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
  &lt;/li&gt;&lt;/ul&gt;";
  }
  </code></pre>
  
  <p>But it outputs : </p>
  
  <pre><code>2012
   - june
  
  2012
   - august
  
  2011
   - july
  </code></pre>
  
  <p>When i group only by year, it will output: </p>
  
  <pre><code>2012
   - june
  2011
   - july
  </code></pre>
  
  <p>i have a "date_posted" row which is datetime (yyyy-mm-dd 00:00:00).
  On top of that i have 1 row for month and 1 for year ( i know that's dumb, but i couldnt figure out how to do this by just using the "date_posted" row.  </p>
  
  <p>Ive read up on some posts on this topic, but its not doing the trick for me. 
  Any help is greatly appreciated!</p>