searls03 Posted June 18, 2012 Share Posted June 18, 2012 ok so I am working on a graphing system with titles of <th scope="col"><?php echo date("F Y", strtotime("-5 months")); ?></th> <th scope="col"><?php echo date("F Y", strtotime("-4 months")); ?></th> <th scope="col"><?php echo date("F Y", strtotime("-3 months")); ?></th> <th scope="col"><?php echo date("F Y", strtotime("-2 months")); ?></th> <th scope="col"><?php echo date("F Y", strtotime("-1 months")); ?></th> <th scope="col"><?php echo date("F Y"); ?></th> what I would like to know is how I could use some buttons or forms to make it so that there are 6 months forward, and 6 months backwards everytime I click on one of the two buttons. any help? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 18, 2012 Share Posted June 18, 2012 Take a look at the optional 2nd parameter for strtotime(). Use the "active" date as that parameter and you should get the +/- months based upon that value. Also, be sure to normalize the date to something like the first of the month. I've seen where descriptions like "+1 months" can give unwanted results. E.g. Jan 31st could give March 2nd because of the short number of days in February. I believe that different versions of PHP handle it differently, but I'd force it to give the values I want rather than assume PHP will do it correctly. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 18, 2012 Author Share Posted June 18, 2012 But what would be a way I could "paginate" the dates. I have a forward 6 months and a backwards 6 months buttons and I would like the dates at the top of the graph to reflect that when I click on them. Any help with that? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 18, 2012 Share Posted June 18, 2012 But what would be a way I could "paginate" the dates. I have a forward 6 months and a backwards 6 months buttons and I would like the dates at the top of the graph to reflect that when I click on them. Any help with that? have you looked at any pagination function, tried to implement any code, or done anything? Pagination is pagination, the concept is the same no matter what you are pagination. There are only a few different parameters that you need to work with when implementing any pagination function. The two most important are the dataset and the number of records per page. For your purposes you already know the dataset: -6, -5, -4 . . . 0 . . . 4, 5, 6. And your records per page is 1. Below is a very basic script that creates single-page pagination based upon a set minimum and maximum integers (-6 and 6). I left out any functionality to convert those values into date displays to leave you somthing to actually do on your own. <?php $min_month = -6; $max_month = 6; $selected_month = 0; if( isset($_GET['month']) && $_GET['month']>=$min_month && $_GET['month']<=$max_month ) { $selected_month = intval($_GET['month']); } //Create month menu $month_menu = ''; //Create prev link $prev = $selected_month-1; $month_menu .= ($selected_month>$min_month) ? "<a href='?month={$prev}'><Prev</a> " : "<Prev "; //Create individual page links for($month=$min_month; $month<=$max_month; $month++) { $month_menu .= ($month!=$selected_month)? " <a href='?month={$month}'>{$month}</a> " : " <b>{$month}</b> "; } //Create next link $next = $selected_month+1; $month_menu .= ($selected_month<$max_month) ? "<a href='?month={$next}'>Next></a> " : " Next>"; ?> <html> <body> Select a month index:<br> <?php echo $month_menu; ?> <br><br> Selected Month Index <?php echo $selected_month; ?><br> </body> </html> Quote Link to comment 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.