adam291086 Posted December 5, 2007 Share Posted December 5, 2007 Say i have a webpage with the url adamplowman.co.uk. If a user clicks on next the url goes to adamplowman.co.uk?m=1. Now if m is there i want to run some script, That i can do. But how do i get it to say if m isn't there then run this script?? Quote Link to comment Share on other sites More sharing options...
matstuff Posted December 5, 2007 Share Posted December 5, 2007 if (!isset($_GET['m'])) { do stuff... } Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 Thanks, Works great. The problem i am now facing is that when i set the url to what i want it returns an odd result. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $nextmonth; ?>?y=<?php echo $thisyear; >">Adam</a></th> Whats happening is when i echo $_GET['m'] i just get the result 1 which is correct. But when i echo $_GET['y'] i get the result ?=2008. I dont want the ?= and just 2008. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 You have to use & if you want more than 1 ID in the URL. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 is this right? <a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $nextmonth; ?>&y=<?php echo $thisyear;?>">Adam</a></th> Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 Yes. Test it and see. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 sorry i had a blond moment. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 sorry i had a blond moment. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 ok all is working well aprt from this. In my claedar i have a next button. //next month $nextmonth = $thismonth+1; if($nextmonth >12) { $thisyear = date('Y')+1; $nextmonth = "1"; } problem being when i get to december 2008 and click next it says january 2008 again. This is due to %thisyear being taken from the current year. How do i get around this and make it say january 2009. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Maybe something along the lines that if current month = Dec, then the next year will be +1 Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 i have done this but still getting the same result if ($monthname == "December") { $thisyear+1; } $monthname is set in the script and return the month name correctly. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Dont you want something to = $thisyear + 1? $thisyear += 1 ? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 edit..... just fixed it with //next month $nextmonth = $thismonth+1; if($nextmonth >12) { $thisyear= $thisyear+1; } Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 I was just pointing out that $thisyear+1; doesn't do anything by itself. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 yeah i realised that after you said it. Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 FYI, short version of $thisyear= $thisyear+1; is $thisyear += 1; Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 ok now i have created a previuos button, problem is that. When i get to january 2009 and click previous i get dec 2008, which is correct. When i click previous again i get nov 2009. Can anyone see why. <?php //previous month $premonth =$thismonth-1; if($premonth <1) { $thisyear = $thisyear-1; $premonth = '12'; } ?> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $premonth; ?>&&y=<?php echo $thisyear;?>">Previous Month</a> just edit the english and the date part Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 YOu have two && in your URL code, not sure if that's effecting it or not. Quote Link to comment Share on other sites More sharing options...
boushley Posted December 5, 2007 Share Posted December 5, 2007 Wouldn't you want to check if $premonth is <= 0... I mean if you have a 12th month, then you can't have a 0th month. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 either way works. But i am still getting the same problem. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 5, 2007 Share Posted December 5, 2007 Just popping in to advise you on building the dynamic URL. & should be replaced with & in all places used. The exception would be header() URLs, etc., but definitely any hyperlinks should be & if you want your HTML to validate. PhREEEk Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 5, 2007 Author Share Posted December 5, 2007 thanks, any idea why the previous part wont work? Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted December 5, 2007 Share Posted December 5, 2007 That is fine, must be something in your other code. Are you setting thisyear = $_GET[y]? Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 5, 2007 Share Posted December 5, 2007 It's not working because you haven't fully grasped how to use date() and mktime() in combination to create a dynamic selector. You'll just need to keep playing with it. Go to php.net and look up the functions: date mktime strtotime strftime The most important part here is, read through the User comments and pick up little bits of code advice through their examples. In many cases, through the user comments, you will see that particular function used just about every creative way possible. But keep trying... all of this learning to use time and date functions is extremely valuable, and many otherwise really good coders unfortunately never git 'r done. PhREEEk Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted December 5, 2007 Share Posted December 5, 2007 Try this to get you started: $month = $_GET['m']; $year = $_GET['y']; $next = mktime(0,0,0,$arr_month[$month]+1,1,$year); $next = $_SERVER['PHP_SELF']."?m=".date("F", $next)."&y=".date("Y", $next); $prev = mktime(0,0,0,$arr_month[$month]-1,1,$year); $prev = $_SERVER['PHP_SELF']."?m=".date("F", $prev)."&y=".date("Y", $prev); 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.