powens Posted December 16, 2010 Share Posted December 16, 2010 Hi, I'd really appreciate some guidance regarding the GET method. Thus far I've developed a calendar that displays a month at a time. I've created a 'next' button (div) that onclick - it submits values via GET. This works well. <div onclick="location.href='cal.php?m=<?php if ($monthly == 12) { $monthly = 1; $yearly++; } else { $monthly++; } echo $monthly?>&y=<?php echo $yearly?>'" id="nextMonth" class="nextMonth next"></div> The complication comes with the 'prev' button, which I thought would be the reverse of the next button (logic wise). <div onclick="location.href='cal.php?m=<?php if ($monthly == 1) { $monthly = 12; $yearly--; } else { $monthly--; } echo $monthly?>&y=<?php echo $yearly?>'" id="prevMonth" class="nextMonth prev"></div> Can you see any reason why this 'prev' button does not work? FYI, This reads GET and initiates the page $m = !empty($_GET["m"]) ? $_GET["m"] : ''; $y = !empty($_GET["y"]) ? $_GET["y"] : ''; if ($m) { $monthly = ($m); $yearly = ($y); } else { $now = time(); $cur_month = date("n", $now); $cur_year = date("Y", $now); $monthly = $cur_month; $yearly = $cur_year; } Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/ Share on other sites More sharing options...
KevinM1 Posted December 16, 2010 Share Posted December 16, 2010 What do you get for the generated hyperlink? In other words, when you hover your mouse over 'prev', are the expected values there when you look at the URL in your browser's status bar? Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148128 Share on other sites More sharing options...
powens Posted December 16, 2010 Author Share Posted December 16, 2010 Neither my 'next' or 'prev' buttons show any information in the status bar when hovered, I presume this has to do with it being a Div onclick event, rather than a hyperlink. - even so, next works. prev doesn't. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148388 Share on other sites More sharing options...
sstangle73 Posted December 16, 2010 Share Posted December 16, 2010 what happens when you press it? What is the url of the new page? Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148395 Share on other sites More sharing options...
powens Posted December 16, 2010 Author Share Posted December 16, 2010 default page url is: cal.php?m=12&y=2010 'next' when clicked = cal.php?m=1&y=2011 again, cal.php?m=2&y=2011 again, cal.php?m=3&y=2011 'prev', when clicked doesn't shift from the default. I'm expecting it to be: m=11&y=2010. Odd? Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148417 Share on other sites More sharing options...
The Letter E Posted December 16, 2010 Share Posted December 16, 2010 I'm probably missing something, but this seems like a lot of work just to display a calendar. You should try working with this: <?php echo shell_exec('cal'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148429 Share on other sites More sharing options...
sstangle73 Posted December 17, 2010 Share Posted December 17, 2010 weird for kicks try changing $yearly-- to $yearly=$yearly-1 idk thats weird why it wouldnt work Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148433 Share on other sites More sharing options...
powens Posted December 17, 2010 Author Share Posted December 17, 2010 Thanks for the replies, things are happening here. Whether positive/negative I'm not too sure. I've altered the 'prev' button to: if ($monthly == 1) { $monthly = 12; $yearly=$yearly-1; } else { $monthly=$monthly-2; } Which now changes the month successfully. However, when in January, it correctly takes it back to December of the previous year, but it sticks at this point. Where I'm expecting it to again shuffle down the months, 11, 10, 9, 8 etc. I don't have much confidence in the fact that its $monthly-2.. strange. Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148444 Share on other sites More sharing options...
DavidAM Posted December 17, 2010 Share Posted December 17, 2010 I think you are getting mixed up by the value of $monthly. Start with the calendar for, say May (month = 5). If you output the DIV for next first, your code is incrementing $monthly. So now it is month 6 (June). If you THEN output the DIV for previous, your code is operating on the NEW value (6), so you have to subtract 2 from it to get the month previous to the current one. Since the code for previous is seeing a $monthly value that is one more than the current month (or it may even be the value 1) your if ($monthly == 1) is not correct. It should actually be if ($monthly == 2). It is confusing. If you make that change it should work, but the next time you read through the code to make changes, you will wonder why you did it that way (trust me, we've all been there). The code will be more clear if you actually add a couple of variables and calculations before generating the DIV's: // untested code off the top of my head $nextMonth = $monthly + 1; if ($nextMonth > 12) { $nextMonth = 1; $nextYear = $yearly + 1; } else { $nextYear = $yearly; } $prevMonth = $monthly - 1; if ($prevMonth < 1) { $prevMonth = 12; $prevYear = $yearly - 1; } else { $prevYear = $yearly; } Or something along those lines. Then output $nextMonth and $prevMonth for the DIV events. Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148446 Share on other sites More sharing options...
sstangle73 Posted December 17, 2010 Share Posted December 17, 2010 David's post seems right the -2 is because when you did the first section for next you already incremented the value by one Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148451 Share on other sites More sharing options...
powens Posted December 17, 2010 Author Share Posted December 17, 2010 Problem solved. Thank you David and others. Quote Link to comment https://forums.phpfreaks.com/topic/221868-unhappy-calendar-get/#findComment-1148453 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.