123guy Posted March 5, 2013 Share Posted March 5, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/275256-list-of-months-with-year/ Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275256-list-of-months-with-year/#findComment-1416651 Share on other sites More sharing options...
123guy Posted March 5, 2013 Author Share Posted March 5, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275256-list-of-months-with-year/#findComment-1416660 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 Ok, so what functions exist in that code? date(), and mktime(), correct? So now that you know what functions you can use, you can search for them in the PHP manual. http://www.php.net/manual/en/function.date.php If you see something in the code that you don't understand, you should always look it up. Quote Link to comment https://forums.phpfreaks.com/topic/275256-list-of-months-with-year/#findComment-1416662 Share on other sites More sharing options...
Psycho Posted March 5, 2013 Share Posted March 5, 2013 <?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>" ?> Quote Link to comment https://forums.phpfreaks.com/topic/275256-list-of-months-with-year/#findComment-1416675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.