Jump to content

list of months with year


123guy

Recommended Posts

hello.  I am trying to figure out how to generate a list of months in a year, with a year attached, so March 2013 for example...  I would like to also paginate these by three months displaying at a time, and it has no limit as to when it stops, thus the pagination of only three months.  I unfortunately don't even know where to start on this, so if anyone has something that could help, or somewhere to send me, that would be awesome!

Link to comment
Share on other sites

I would ask "What have you tried", but I'm guessing you're going to say you don't know what to try. So instead, have you tried google.com?

 

Hopefully I'm not seeming rude by this, but you should always try to figure out the problem on your own with Google as a tool, then if you still can't figure it out after following a couple of tutorials, then ask the question with a good bit of detail.

Link to comment
Share on other sites

ok, so I found this code to get me started with the displaying three months at a time.

 

$list = array(date('n')); 
$list[]=date('n', mktime(0, 0, 0, $list[0]+1, 1));  
$list[]=date('n', mktime(0, 0, 0, $list[0]+2, 1));  

foreach ($list as $i) {  
   echo "$i";  
}

 

Problem with this is the fact that there is not pagination.  I know how to set up the months to paginate, but I do not know how to set up the year to start a new year in january.  I could make it say jan 2013, march 2013...dec 2013, jan 2013...etc.  I need it to move to jan 2014 at the end though.  any help?

Link to comment
Share on other sites

 

<?php

$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
$currMonth = date('n');

$list = array();
$list[] = mktime(0, 0, 0, $currMonth+$offset-1, 1);
$list[] = mktime(0, 0, 0, $currMonth+$offset,   1);
$list[] = mktime(0, 0, 0, $currMonth+$offset+1, 1);

foreach ($list as $dateTS)
{
   echo date('M Y', $dateTS) . ' ';
}

$prev = $offset-3;
$next = $offset+3;
echo "<br><a href='?offset={$prev}'>Prev</a> <a href='?offset={$next}'>Next</a>"

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.