View Single Post
Old 03-08-2008, 06:50 PM   #7 (permalink)
DeMo
The Contributor
 
DeMo's Avatar
 
Join Date: Jan 2008
Location: Brazil
Posts: 77
Thanks: 14
DeMo is on a distinguished road
Default

If the type of the added column is DATE or DATETIME you can do it with a simple query:
SQL Code:
SELECT DISTINCT MONTHNAME(`added`) AS `month`, YEAR(`added`) AS `year` FROM `news` ORDER BY `year` DESC, `month` DESC

This will return a table like this:
Code:
+--------+  +------+
| month  |  | year |
+--------+  +------+
|March   |  | 2008 |
|February|  | 2008 |
|January |  | 2008 |
|December|  | 2007 |
+--------+  +------+
Now to display the list you simply do:
PHP Code:
while ($q1 mysql_fetch_array($q)) {
  echo 
$q1['month'] . "/" $q1['year'];

You can also increment that query to ignore the current month/year and to limit the number of results (let's say you want only 5 links):
SQL Code:
SELECT DISTINCT MONTHNAME(`added`) AS `month`, YEAR(`added`) AS `year` FROM `news` WHERE MONTH(`added`) != MONTH(NOW()) AND YEAR(`added`) != YEAR(NOW()) ORDER BY `year` DESC, `month` DESC LIMIT 5
Send a message via ICQ to DeMo Send a message via MSN to DeMo Send a message via Skype™ to DeMo
DeMo is offline  
Reply With Quote