86Stang Posted January 11, 2007 Share Posted January 11, 2007 Hi all,I have an itinerary code that takes the start date and end date from the user and spits out all events happening between those dates. However, recently, the script won't work properly. It will work so long as the dates I pick have two characters in them which leads me to believe that it's a formating issue. What I believe will solve this is if I can find a way, in the drop down menus where it shows the selectable days/months with the leading zeros. Right now it's "1, 2, 3 .... 9, 10, 11, 12, ..." and I'd like to get it to "01, 02, 03 .... 09, 10, 11, 12, ..."Here's my code for that section:[code]$cur_month = date('m');$cur_day = date('d');$cur_year = date('Y');$total_days = date('t');$month_start = "<select name=\"start_month\">";$month_end = "<select name=\"end_month\">";for ($i=1;$i<=12;$i++) { if ($i == $cur_month) { $month_start .= "<option value=\"$i\" selected>$i</option>\n"; $month_end .= "<option value=\"$i\" selected>$i</option>\n"; } else { $month_start .= "<option value=\"$i\">$i</option>\n"; $month_end .= "<option value=\"$i\">$i</option>\n"; } }$month_start .= "</select>";$month_end .= "</select>";[/code]It's probably something to do with the formating of the FOR loop but I'm just not getting it. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/ Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 if($i<10){$i = "0".$i;} Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158362 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 I can't seem to edit my post. To clarify, that would go:[code]for ($i=1;$i<=12;$i++){ if ($i == $cur_month){ if($i<10){ $i = "0".$i; } $month_start .= "<option value=\"$i\" selected>$i</option>\n"; $month_end .= "<option value=\"$i\" selected>$i</option>\n"; }else{ if($i<10){ $i = "0".$i; } $month_start .= "<option value=\"$i\">$i</option>\n"; $month_end .= "<option value=\"$i\">$i</option>\n"; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158368 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Jessi,I noticed the same thing, there's a time limit. You can only edit your post upto a certain amount of time after it's been posted. Another 'bug' with the upgrade I'd imagine.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158372 Share on other sites More sharing options...
86Stang Posted January 11, 2007 Author Share Posted January 11, 2007 Jesi, it worked like a champ. Whatever they're paying you, it's not enough!! :PCan't I mark this as solved? Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158374 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 I concur :) Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158375 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 [quote author=86Stang link=topic=121971.msg502374#msg502374 date=1168534242]Can't I mark this as solved?[/quote]I believe that they're working on the mod for that now, it needs a few changes since the forum upgrade two days ago.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158377 Share on other sites More sharing options...
86Stang Posted January 11, 2007 Author Share Posted January 11, 2007 Yeah, I don't know why I thought it had such a feature. Must be lack of coffee... ??? Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158395 Share on other sites More sharing options...
emehrkay Posted January 11, 2007 Share Posted January 11, 2007 you should shorten up your code. props to jessiif ($i == $cur_month){ if($i<10){ $i = "0".$i; } $month_start .= "<option value=\"$i\" selected>$i</option>\n"; $month_end .= "<option value=\"$i\" selected>$i</option>\n"; }else{ if($i<10){ $i = "0".$i; } $month_start .= "<option value=\"$i\">$i</option>\n"; $month_end .= "<option value=\"$i\">$i</option>\n"; }to$selected = ($i == $cur_month) ? 'selected = "selected"' : ''; if($i<10){ $i = "0".$i; } $month_start .= "<option value=\"$i\" $selected >$i</option>\n"; $month_end .= "<option value=\"$i\" $selected >$i</option>\n";i used a terany(sp)(clause) ? if true : if false Quote Link to comment https://forums.phpfreaks.com/topic/33773-proper-format-for-date-drop-down-menu/#findComment-158398 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.