I want to have a list of months and years when content was posted to my website. Example:

///

Archive
July 2012
June 2012
May 2012
April 2012

///

Then, clicking one of list items takes you to a page with every post from that month. I know I should setup two columns in my mysql table, month and year. From there, I don't know how to get PHP to build a list using the data. I could do it manually every time a new month comes up, but that defeats the purpose in my book.

Please help me, Internet :)

here, I don't know how to get PHP to build a list using the data. I could do it manually every time a new month comes up, but that defeats the purpose in my book.

Hello,

Basically (From what I understand) you should have a table/column that populates a list of months, from this month, the form should handle it by a $_GET method. So for example:

yoursite.com/Archive.php?month=january

and the php would be like this:

<?php

  $month = $_GET['month'];

  // rest of php code

 ?>

You can populate the form (list of months) by a query.

Sorry it's not much help, message back if you require any further code snippets!

I believe the code you posted was for pulling rows linked to a certain month, right? That helped, but I need to tell PHP to find each unique combination of months and years throughout the table, and then echo a link for each combo.

I could tell it to echo a link using the month and year from each row it finds, but then I could end up with twenty "August 2012"s or something

Maybe instead of two columns for month/year, use one column with the date formated as whatever month/year format you like, then select unique entries from that column for the unique months.

That was exactly what I needed :) Thank you very much good sir.

In addition, if you have a timestamp column, then there's no need to add two additional columns. Just use YEAR() and MONTH() in your query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.