itchy8me Posted August 31, 2008 Share Posted August 31, 2008 Hello I'm having problems with a piece of code i wrote (pasted in the code quote). Its been working for a month now on my webserver and all of a sudden today it doesn't work anymore. The code iterates ($i) the month in mktime() to create a date() and extract the month from it. However it has now started printing 1 month number for every two iterations as shown in the screen capture below( the number after the dash is the value of $i). echo "</SELECT>- <SELECT name=\"ETA_month$ii\">"; for($i = 1; $i <= 12; ++$i) { echo "<OPTION value=\""; echo date("m", mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y"))); echo "\""; if($time_1_parse[month] == date("m", mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y")))) { echo " selected='true'"; }; echo ">"; echo date("m", mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y"))); echo "-$i</OPTION>"; //echo date("m", mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y"))); } echo "</SELECT>"; am i doing something wrong that i overlooked? or is this a bug? kind regards, Wernher Quote Link to comment Share on other sites More sharing options...
itchy8me Posted August 31, 2008 Author Share Posted August 31, 2008 sorry i just noticed that i'm doing some very naughty things in that bit of code, solved it by only using number iterations and no date creations (why make it hard for myself?) doh! Quote Link to comment Share on other sites More sharing options...
itchy8me Posted August 31, 2008 Author Share Posted August 31, 2008 okay, i think i'm not understanding something about the functions date() or mktime(). Having certain suspicions about the above mentioned code, i left the code(in the 1st post) running on my localhost to see what would happen when the month turned 09.. i nearly lost my head.. the iteration of the month now has one entry per month again.. like they where doing yesterday and a month before.. wtf!? what is it that am doing wrong in the above code? Quote Link to comment Share on other sites More sharing options...
itchy8me Posted September 1, 2008 Author Share Posted September 1, 2008 anybody have any ideas? Quote Link to comment Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 from looking at your code, the only think I can suggest is not re-iterating the date() funcion so much... easy buffer overflow right there.. just a thought anyway Quote Link to comment Share on other sites More sharing options...
itchy8me Posted September 1, 2008 Author Share Posted September 1, 2008 nice programming tip thanks, i have now changed the code to the following: echo "</SELECT>- <SELECT name=\"ETA_month$ii\">"; for($i = 1; $i <= 12; ++$i) { $date_iterate = mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y")); echo "<OPTION value=\""; echo date("m", $date_iterate); echo "\""; if($time_1_parse[month] == date("m", $date_iterate)) { echo " selected='true'"; }; echo ">"; echo date("m", $date_iterate); echo "-$i</OPTION>"; //echo date("m", mktime(date("H"), date("i"), date("s"), $i, date("d"), date("Y"))); } echo "</SELECT>- <SELECT name=\"ETA_year$ii\">"; However, setting my system clock back to yesterday, 31st of august, i see that the error still occurs, that is : 2 iterations for the date number to change (as shown in the image from the first post). Anymore ideas? :-D Quote Link to comment Share on other sites More sharing options...
itchy8me Posted September 1, 2008 Author Share Posted September 1, 2008 so, am i doing something wrong, or should a make a bug report? Quote Link to comment Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 ok so just so I have the jist of this, only on certaint days it does this... I would say its possible for both, I would double check all your coding, check again if you set your clock back to the regular date/time, then set it back to aug. 31 and it does it.. then it could very welll be a bug, I don't see why its doing that, it could also be something else in your script somewhere else as well. So I would double check that too. Quote Link to comment Share on other sites More sharing options...
itchy8me Posted September 1, 2008 Author Share Posted September 1, 2008 good idea. i'm going to have a look tonight on what dates it does this. will report back. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 2, 2008 Share Posted September 2, 2008 OK, it's not a bug guys. It looks like the code is trying to determine the month number by creating a date object using todays date and only changing the month. This post was submitted yesterday on Aug. 31, 2008. If you only tried to change the month value you get Feb. 31, 2008 - no such date exists! It would actually evaluate to March 3, 2008! Which is why the select list shows 03-2. I think that code is way over complicated. It doesn't look like you need to do all the date evaluations. All you need to know is the month number of the current month. echo "</SELECT>- <SELECT name=\"ETA_month$ii\">"; $current_month = date('m'); for($month=1; $month<=12; $month) { $selected = ($month == $current_month) ? ' selected="selected"' : ''; echo "<OPTION value=\"$month\"$selected></option>"; } echo "</SELECT>- <SELECT name=\"ETA_year$ii\">"; 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.